【问题标题】:Give a single figure multiple captions in rmarkdown pdf_book output在 rmarkdown pdf_book 输出中为单个图形提供多个标题
【发布时间】:2021-09-07 20:28:53
【问题描述】:

我正在用 bookdown 写论文。我想包含一个图形列表,但我不想包含每个图形的全部标题。我的想法是给每个图一个出现在lof 中的标题和第二个没有出现的标题。我尝试使用fig.subcap 来做到这一点,但这并没有给出第二个标题,我想是因为它需要第二个数字存在。

在下面的示例中,我想创建一个带有标题 "My Main Caption. Here is more detail" 的图形,但在 lof 中只有:"My Main Caption"

---
title: "Queries"
header-includes:
- \usepackage{subfig}
output: 
  bookdown::pdf_book:
    toc: true
lof: yes
---


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


```{r irisfig, fig.cap='My Main Caption. Here is more detail'}
ggplot2::ggplot(iris, aes(Sepal.Length, Sepal.Width))+
  geom_point()

这不起作用:

```{r irisfig2, fig.cap='My Main Caption.', fig.subcap= c('Here is more detail')}
ggplot2::ggplot(iris, aes(Sepal.Length, Sepal.Width))+
  geom_point()

【问题讨论】:

    标签: r latex r-markdown caption subfigure


    【解决方案1】:

    LaTeX 命令\caption 提供了一个可选参数来为目录指定更短的标题,格式为\caption[Short caption]{Long caption}。此选项可通过标题中的fig.scap 访问:

    ```{r irisfig2, echo=F, fig.cap='My Main Caption PLUS More Detail', fig.scap='My Main Caption', out.extra=''}
    ggplot2::ggplot(iris, aes(Sepal.Length, Sepal.Width))+
      geom_point()
    ```
    

    产生乳胶代码:

    \begin{figure}
    \includegraphics{test9_files/figure-latex/irisfig2-1} 
    \caption[My Main Caption]{My Main Caption PLUS More Detail}\label{fig:irisfig2}
    \end{figure}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-08
      • 2018-08-29
      • 1970-01-01
      • 2017-12-15
      • 2015-11-28
      • 2019-10-09
      • 2017-12-14
      • 2017-01-28
      相关资源
      最近更新 更多