Rmarkdown如何在图标题中添加脚注

7

我希望在呈现为PDF和HTML的R markdown报告中,在图例标题中包含脚注(该报告基于bookdown/thesisdown/huskydown)。

理想情况下,使用文本引用会更好:

(ref:foo-footnote) Text in the footnote.
Can span multiple lines, but has to start on the line of the text reference.

(ref:foo-caption) My text with a footnote.^[(ref:foo-footnote)]

我尝试的方法

---
title: "Footnote in Caption"
author: "Test"
output: html_document
#output: pdf_document
---

## Figure with caption which includes a footnote
<!-------------------------------------------------------------------->
<!-- Reference the figure "by number" as usual with \@ref(fig:foo) -->
<!-- Reference the figure "by name" by adding an anchor above the figure: -->
<!-- \hypertarget{fig:foo}{} -->
<!-- which can be referenced by: -->
<!-- [my linked text](#fig:foo) -->

(ref:foo-caption) My caption^[Footnote text.].
(ref:foo-scaption) My short caption

```{r foo, echo=FALSE, out.width='100%', fig.align = "center", fig.cap='(ref:foo-caption)', fig.scap='(ref:foo-scaption)'}
knitr::include_graphics(paste0(fig_path,"foo.png"), auto_pdf = TRUE)
# if auto_pdf = TRUE: includes PDF version of figure if available in same folder
```
1个回答

1
这里有一个关于从bookdown生成PDF输出的可重现示例,但我还没有想出如何使其适用于HTML。
基本上,你需要在图表标题中包括\\protect\\footnotemark,然后在Rmd文本中(代码块之外)使用\footnotetext{这里是脚注文本。}来添加你的文本。
---
title: "Footnote in caption"
output: 
  bookdown::pdf_document2: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(bookdown)
```

```{r pressure, echo=FALSE, fig.cap="This is a figure caption with a footnote.\\protect\\footnotemark", out.width="100%"}
plot(pressure)
```

\footnotetext{Here is the footnote text.}

Here is a plot in Figure \@ref(fig:pressure). 

原始的LaTeX解决方案来自于Tex StackExchange (https://tex.stackexchange.com/questions/10181/using-footnote-in-a-figures-caption),我只是为Rmd进行了适应,需要在标题中使用双斜杠来表示LaTeX命令。


这对我来说只是部分有效。它使得Rmarkdown文件跳过一个脚注号,并将相应的脚注放在图像上面的页面上。 - missgwolf

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接