Rmarkdown与html,如何引用数字?

mja*_*ews 7 knitr r-markdown bookdown

使用 RMarkdown 我总是通过 Rmd -> pandoc -> TeX -> pdflatex -> pdf 生成 pdf 文档,并使用以下示例中的方式\\label{something}完成图形引用:fig.cap

---
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))
```
Run Code Online (Sandbox Code Playgroud)

如果我更改output: pdf_documentoutput: 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))
```
Run Code Online (Sandbox Code Playgroud)

但以下确实有效:

---
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))
```
Run Code Online (Sandbox Code Playgroud)

这是否意味着从 Rmarkdown 生成 html 时交叉引用数字的唯一方法是使用output: bookdown::html_document2. 如果是的话,那很好,但是我错过了什么吗?

mja*_*ews 4

听完谢益辉的说法,我认为我们可以理所当然地认为,是的,在 rmarkdown 中的 html_document 中进行图形交叉引用的唯一方法是

---
output: bookdown::html_document2
---
Run Code Online (Sandbox Code Playgroud)

在标题中。