如何使用 Rmarkdown 自定义标题?

Ale*_*era 3 pdf pdf-generation r r-markdown

我目前正在使用Rmarkdownon处理 pdf 文档,RStudio但我对如何自定义 YAML 部分感到非常困惑。这是我的实际代码:

---
title: "The very basics of R"
author: "Alejandro C."
date: "March, 2020"
output:
  pdf_document: 
    latex_engine: xelatex
    toc: true

mainfont: Times New Roman
fontsize: 12pt
header-includes:
  - \usepackage{titling}
  - \pretitle{\begin{flushleft}}
  - \posttitle{\end{flushleft}}  
  - \preauthor{\begin{flushleft}}
  - \postauthor{\end{flushleft}}  
  - \predate{\begin{flushleft}}
  - \postdate{\end{flushleft}}  

---
Run Code Online (Sandbox Code Playgroud)

我想要实现的是以下内容:

  • 在我的标题中使用更大的字体大小(例如,14)并将其加粗
  • 对作者和日期使用 12 字体大小
  • 为我的文档使用 11 fontsize(我不知道这是否必须在 YAML 部分中指定)

我是这个话题的新手,所以除了R Markdown Reference Guide之外,我真的不知道从哪里开始。任何帮助和建议将不胜感激。

Car*_*era 5

您可以LaTeX在 YAML 部分中包含命令,以便您可以更改字体的大小、形状和外观。请注意,您需要\在 YAML 部分复制(反斜杠)。

在下面的 MWE 中,使用了以下命令:

  • \textit{}
    • \\textit{} 在 YAML 中
    • 使字母斜体
  • \textbf{}
    • \\textbf{} 在 YAML 中
    • 使字母加粗
  • \fontsize{14pt}{3pt}\\selectfont
    • \\fontsize{14pt}{3pt}\\selectfont 在 YAML 中
    • 使字母 14pt 与 3pt 换行符

正如@Marius here所建议的那样,您可能希望在简单的降价语法之外进一步自定义输出。所以,最好设置keep_tex: true为这样的场合。

移动电源

---
title: "\\fontsize{14pt}{3pt}\\selectfont \\textbf{\\textit{The very basics of R}}"
author: "\\fontsize{12pt}{3pt}\\selectfont Alejandro C."
date: "\\fontsize{12pt}{3pt}\\selectfont March, 2020"
output:
  pdf_document: 
    latex_engine: xelatex
    toc: true
    keep_tex: true
mainfont: Times New Roman
fontsize: 11pt
header-includes:
  - \usepackage{titling}
  - \pretitle{\begin{flushleft}}
  - \posttitle{\end{flushleft}}  
  - \preauthor{\begin{flushleft}}
  - \postauthor{\end{flushleft}}  
  - \predate{\begin{flushleft}}
  - \postdate{\end{flushleft}}  
---

# Lorem Ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incidunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint 
obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est 
laborum.
Run Code Online (Sandbox Code Playgroud)

输出

在此处输入图片说明