为 Rmarkdown 的 YAML header 中的图形设置标题字体大小

Set caption font size for figures in YAML header of Rmarkdown

我正在使用 Rstudios markdown 编写一份报告,我想使用 Latex 将其编译为 pdf 以及 html...

是否可以通过某种方式调整 ![caption](figure.jpg) 环境中包含的图像的字幕字体大小?目前 html 中的字幕看起来与文本的其余部分相似。

您可以使用 css 来控制它。例如:

<style type="text/css">
.caption {
    font-size: x-small;
}
</style>

![caption](figure.jpg)

有关可用的 font-size 选项,请参阅 css 指南,例如 this

这个答案显然已经被接受,但为了完整起见,我添加了问题的 PDF 方面。

如果您想更改 PDF 文档的标题字体大小,我建议您通过以下两种方法之一使用 caption 包:

header-includes - 选项:

---
title: "Title"
author: "Jorge Luis Borges"
header-includes:
  - \usepackage[font={small}]{caption}
output:
  pdf_document
---

这里的重点是font={<font options>}.

in_header - 选项:

---
title: "Title"
author: "Jorge Luis Borges"
output:
  pdf_document:
    includes:
      in_header: style.tex
---

其中 style.tex 包含在包含 .Rmd 文件的同一目录中。 style.tex 文件需要包含 \usepackage[font={small}]{caption}.

和之前一样,这里的重点是font={<font options>}


使用 caption 包,您有大量自定义选项,仅举几例,见下文:

  • scriptsize = 非常小
  • footnotesize = 通常用于脚注的大小
  • small = 小尺寸
  • large = 大码
  • it = 斜体
  • bf = 粗体

如需完整参考,请访问 official documentation

此外,一些 cross-references TexSE 网站上的文章:

Change the font of figure captions

How to include Latex package in RMarkdown

感谢@Johnny 之前的评论,我想对 pdf 报告中的图形标题进行更多修改。我想要一个如下所示的标题:

Figure 1. This is a graph to explain productivity.

要获取此内容,请在 YAML 中添加:

---
title: "Title"
author: "Author"
header-includes:
  - \usepackage[font={small,it}, labelfont={bf}]{caption}
output:
  pdf_document
---