【问题标题】:Rmarkdown with html, how to reference figures?rmarkdown用html,如何引用数字?
【发布时间】: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


【解决方案1】:

听过Yihui Xie,我想我们可以想当然地认为是的,在rmarkdown的html_document中做图形交叉引用的唯一方法就是做

---
output: bookdown::html_document2
---

在标题中。

【讨论】:

    猜你喜欢
    • 2018-10-14
    • 2023-01-29
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    相关资源
    最近更新 更多