带有HTML的Rmarkdown,如何参考数字?

时间:2019-01-10 20:02:20

标签: r-markdown knitr 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))
```

如果我将output: pdf_document更改为output: html_document,那是行不通的,这可以理解,因为它依赖于LaTeX的交叉引用系统。

那么Figure引用如何与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。如果可以的话,那很好,但是我想念什么吗?

1 个答案:

答案 0 :(得分:0)

从谢艺辉那里得知,我认为我们可以认为是的,在rmarkdown中html_document中进行图形交叉引用的唯一方法是做

---
output: bookdown::html_document2
---
标题中的

相关问题