knitr:我可以使用fig.cap块选项引用图标题中的文章吗?

Tom*_*rop 8 r knitr r-markdown

我想在我的图标题中引用一篇文章.我试过在块选项中使用Rmarkdown/pandoc [@citekey]和latex \\citep{citekey}形式,fig.cap没有任何运气.

这是一个可重复的例子:

---
output:
  rmarkdown::tufte_handout
references:
- id: Nobody06
  title: 'My Article'
  author:
  - family: Nobody
    given: Jr
  issued:
    year: 2006
---

Some text [@Nobody06].

```{r figure, fig.cap="A figure [@Nobody06]"}
library(ggplot2)
qplot(1:10, rnorm(10))
```

# References
Run Code Online (Sandbox Code Playgroud)

这会在文本块中生成正确的引文,但在图标题中[@Nobody06](当我使用RMarkdown表单时)或(?)(当我使用Latex表单时).

这是一个screencap: 撷取画面.

有谁知道是否可以在fig.cap现场使用引用?

Mic*_*per 4

bookdown包扩展了 rmarkdown 的功能并提供了一些有用的工具文本引用可以用来解决这个问题。正如包作者所述,可以使用文本引用:

您可以将一些文本分配给标签,并在文档中的其他位置使用该标签引用该文本。

这对于引用非常有效,如下所示:

---
output: bookdown::tufte_handout2
references:
- id: Nobody06
  title: 'My Article'
  author:
  - family: Nobody
    given: Jr
  issued:
    year: 2006
---


(ref:crossref) Some text [@Nobody06].

```{r figure, fig.cap="(ref:crossref)"}
library(ggplot2)
qplot(1:10, rnorm(10))
```

# References
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

您会注意到输出格式已调整为bookdown::tufte_handout2可以使用预订功能。您可以在此处找到输出格式的完整列表。

在此处阅读有关文本参考的更多信息:https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#text-references