【问题标题】:Rmarkdown add footnote to figure captionRmarkdown 为图形标题添加脚注
【发布时间】:2020-11-10 15:08:23
【问题描述】:

我想在呈现为 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)]

我尝试了什么

---
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
```

【问题讨论】:

    标签: r r-markdown bookdown caption footnotes


    【解决方案1】:

    这是来自bookdown 的 PDF 输出的可重现示例,但我还没有弄清楚如何使它适用于 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 命令。

    【讨论】:

      猜你喜欢
      • 2019-09-08
      • 2016-05-15
      • 1970-01-01
      • 2013-02-19
      • 1970-01-01
      • 2015-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多