簡體   English   中英

Rmarkdown 為圖形標題添加腳注

[英]Rmarkdown add footnote to figure caption

我想在 R markdown 呈現給 PDF 和 HTML 的報告(報告基於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
```

這是 bookdown 的bookdown輸出的可重現示例,但我還沒有弄清楚如何使其適用於 HTML。

本質上,您需要在圖形標題中包含\\protect\\footnotemark ,然后在 Rmd 文本(塊外)中包含\footnotetext{Here is the footnote text.}和您的文本。

---
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 命令的雙斜杠。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM