轻松记录您
灵感和创意

rmarkdown 如何交叉引用图形和表格解决方案

您可以使用输出格式bookdown::pdf_document2而不是pdf_document,并且引用图形的语法为\@ref(fig:chunk-label)。 有关详细信息,请参见文档
我无法使用knitr生成\ label {fig:mwe-plot}之后,将\label{…}添加到标题参数将在基础tex文件中生成标签,即

{r fig1, echo=FALSE, fig.cap="\\label{fig:fig1}This is a caption"} plot(mtcars$wt, mtcars$mpg) {{EJS0}} 您可以尝试使用字幕工具包。 您可以在此链接中找到示例。 就我而言,我包括一个代码块,其中: table_captions <- captioner::captioner(prefix="Tab.") figure_captions <- captioner::captioner(prefix="Fig.") t.ref <- function(label){ stringr::str_extract(table_captions(label), "[^:]*") } f.ref <- function(label){ stringr::str_extract(figure_captions(label), "[^:]*") } 定义代码块时,我在表格和图形中包含标题,如下所示: {r chunk_creating_one_figure, echo=FALSE, fig.cap=figure_captions(“one_figure”, “figure label”)}
plot(1)

要么

```{r chunk_creating_one_table, echo=FALSE, fig.cap=table_captions("one_table", "table label")}
knitr::kable(data.frame(col="something"), format="markdown")

在我的所有Rmarkdown中,引用都作为inline_text包含在内:

As shown in figure r f.ref("one_figure")
Data is shown on table r t.ref("one_table")

未经允许不得转载:坚果云Markdown » rmarkdown 如何交叉引用图形和表格解决方案
分享到: 更多 (0)

坚果云Markdown轻松记录您 灵感和创意

坚果云Markdown下载坚果云Markdown介绍