mav*_*cks 5 r caption footnotes r-markdown bookdown
我想包括图题中的一个脚注中呈现为PDF和HTML的R降价报告(报告是基于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)]
Run Code Online (Sandbox Code Playgroud)
---
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
```
Run Code Online (Sandbox Code Playgroud)
小智 2
这是 PDF 输出的可重现示例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).
Run Code Online (Sandbox Code Playgroud)
原始 LaTeX 的原始解决方案来自 Tex StackExchange ( https://tex.stackexchange.com/questions/10181/using-footnote-in-a-figures-caption ),我刚刚适应了 Rmd,这需要您使用字幕内的 LaTeX 命令的双斜杠。