gpt4 book ai didi

r - 如何使用 Rmarkdown 自定义标题?

转载 作者:行者123 更新时间:2023-12-04 02:39:42 25 4
gpt4 key购买 nike

我目前正在 RStudio 上使用 Rmarkdown 处理 pdf 文档,但我对如何自定义 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}}

---

我想要实现的是:

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

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

最佳答案

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

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

  • \textit{}
    • \\textit{} YAML
    • 将字母设为斜体
  • \textbf{}
    • \\textbf{} YAML
    • 将字母设为粗体
  • \fontsize{14pt}{3pt}\\selectfont
    • \\fontsize{14pt}{3pt}\\selectfont YAML
    • 使用 3pt 换行使字母为 14pt

正如@Marius 建议的那样 here ,您可能希望在简单的 markdown 语法之外进一步自定义输出。因此,最好为这种情况设置keep_tex: true

MWE

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

输出

enter image description here

关于r - 如何使用 Rmarkdown 自定义标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59958677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com