【问题标题】:Caption at the top of the image. Option from chunk rmardown图片顶部的标题。来自块 rmarkdown 的选项
【发布时间】:2021-12-20 09:26:16
【问题描述】:

你能在 rmarkdown 中生成图形的块上设置标题选项吗?

当我们使用标题作为代码片段(块)中生成的图形的标题时,会为 .pdf 生成包含图形下方标题的乳胶输出。我已阅读文档,但找不到配置在图形图像之前定义标题的乳胶输出的方法。

1.升级


{r, echo=FALSE, eval=TRUE, fig.cap="CAPTION", fig.pos="H"}

【问题讨论】:

    标签: latex r-markdown knitr


    【解决方案1】:

    “float”包与 kable 和 kableExtra 一起使用。

    当我们需要将图形的标题放在顶部时,我发现的唯一解决方案是使用“floatrow”包。

    由于“float”和“floatrow”不兼容,所以需要在“floatrow”中添加一些额外的配置,使kable和kableExtra使用rstudio、rmarkdown和knitr生成的表格外观一致。

    
    header-includes:
     - \usepackage{floatrow}
     - \floatsetup[figure]{capposition=top} % Caption figure top.
     - \floatsetup[table]{capposition=top} % Caption table top.
     - \floatplacement{figure}{H} % Figure position according to the code flow.
     - \floatplacement{table}{H} % Table position according to the code flow.
     - \floatsetup[longtable]{margins=centering} % Longtable tables centered.
    
    

    【讨论】:

      【解决方案2】:

      您应该使用 package{caption}

      中的\captionof
      ---
      title: "R Notebook"
      header-includes:
      - \usepackage{caption}
      - \usepackage{graphicx}
      output:
        pdf_document: default
      ---
      
      \captionof{figure}{Text of the caption.}
      ```{r, echo=FALSE}
      library(ggplot2)
      
      k <- ggplot(mpg, aes(displ, hwy, colour = class)) + 
        geom_point() + 
          theme(plot.margin = unit(c(0,0,0,0), "cm"))     
      k
      ```
      \centering
      \captionof{figure}{Text of the caption.}
      \includegraphics{your_pic.png}
      

      【讨论】:

      • 感谢您的回答。但我正在使用 rmarkdown 和 knitr 从 rstudio 生成 .pdf 文档。您提出的解决方案将迫使我在编译为 .pdf 之前修改 .tex 代码。
      • @JoséCarlos 是的,你是对的。但是你已经找到了非 LaTeX 的解决方案?
      • 是的,我添加一个答案。
      猜你喜欢
      • 2015-02-11
      • 1970-01-01
      • 2015-10-05
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 1970-01-01
      • 1970-01-01
      • 2021-01-08
      相关资源
      最近更新 更多