首页 > 解决方案 > 交叉引用和标题在 Rmd 文件中不起作用

问题描述

任何人都可以帮助我了解如何编写我的标题,以便图形标题和交叉引用有效吗?

我正在练习制作标题并交叉引用我的 Rmd 文件中的一个简单图。我知道要这样做,我应该在标题中添加:“输出:bookend::pdf_document2”和“fig_caption = yes”。然后,在一个名为 myfigure 的块中,我应该添加“fig.cap =”\label{fig:myfigure} My caption”。要交叉引用这个图,我应该在文本中写入“@ref(fig:myfigure)”。我的代码如下。它不会编织,因为标题的格式错误。

---
title: "knit"
author: "Chase Hommeyer"
date: "4/1/2019"
output: bookdown::pdf_document2
  toc: true
  fig_caption: yes
---

```{r myfigure, fig.cap = "\\label{fig:myfigure} My caption"}
plot(pressure)
```

My plot is called \@ref(fig:myfigure).

然后,我尝试删除 toc 和 fig_caption 之前的空格,它编织,但没有出现标题,并且文本字面上打印“@ref(fig:myfigure)”而不是交叉引用。我试过的标题在这里:

---
title: "knit"
author: "Chase Hommeyer"
date: "4/1/2019"
output: bookdown::pdf_document2
toc: true
fig_caption: yes
---

我还尝试将“pdf_document:”添加到标题中,但同样的问题是没有标题,并且交叉引用实际上是“@ref(fig:myfigure)”。我试过的这个标题在这里:

 ---
title: "knit"
author: "Chase Hommeyer"
date: "4/1/2019"
output: bookdown::pdf_document2
  pdf_document:
    toc: true
    fig_caption: yes
---

任何人都可以帮助我了解如何编写我的标题以使其正常工作吗?

标签: rlatexr-markdownpdflatexcaption

解决方案


使用\ref{fig:myfigure}而不是\\@ref(fig:myfigure)

请参阅RStudio 社区帖子


推荐阅读