【发布时间】:2019-06-05 18:17:46
【问题描述】:
使用 RMarkdown,我总是通过 Rmd -> pandoc -> TeX -> pdflatex -> pdf 生成 pdf 文档,并在 fig.cap 中使用 \\label{something} 完成图形引用,如下例所示:
---
title: "Foo"
author: "Mark Andrews"
date: "10 January 2019"
output: pdf_document
---
See Figure \ref{figfoo} and see Figure \ref{figbar}.
```{r fig1, fig.cap='A figure\\label{figfoo}'}
plot(rnorm(10))
```
```{r fig2, fig.cap='Another figure\\label{figbar}'}
plot(rnorm(10))
```
如果我将output: pdf_document 更改为output: html_document,这不起作用,这是可以理解的,因为它依赖于 LaTeX 的交叉引用系统。
那么图引用如何在 RMarkdown 中与 html_document 一起使用?
以下不起作用:
---
title: "Foo"
author: "Mark Andrews"
date: "10 January 2019"
output: html_document
---
See Figure \@ref(fig:fig1) and see Figure \@ref(fig:fig2).
```{r fig1, fig.cap='A figure}'}
plot(rnorm(10))
```
```{r fig2, fig.cap='Another figure'}
plot(rnorm(10))
```
但以下方法确实有效:
---
title: "Foo"
author: "Mark Andrews"
date: "10 January 2019"
output: bookdown::html_document2
---
See Figure \@ref(fig:fig1) and see Figure \@ref(fig:fig2).
```{r fig1, fig.cap='A figure}'}
plot(rnorm(10))
```
```{r fig2, fig.cap='Another figure'}
plot(rnorm(10))
```
这是否意味着在从 Rmarkdown 生成 html 时交叉引用数字的唯一方法是使用 output: bookdown::html_document2。没关系,如果是这样,但我错过了什么吗?
【问题讨论】:
-
答案是肯定的。这是我所知道的唯一可移植方式。
标签: r-markdown knitr bookdown