如何使用Rmarkdown自定义标题?
我目前正在使用如何使用Rmarkdown自定义标题?,r,pdf,pdf-generation,r-markdown,R,Pdf,Pdf Generation,R Markdown,我目前正在使用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
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 fontsize(我不知道是否必须在YAML部分中指定)
对于这个话题我是新手,所以我真的不知道从哪里开始。任何帮助和建议都将不胜感激。您可以在YAML部分包含
LaTeX
命令,以便更改字体的大小、形状和字体。请注意,您需要在YAML部分中复制\
(反斜杠)
在以下MWE中,使用以下命令:
\textit{}
- YAML中的
\\textit{}
- 使字母斜体
- YAML中的
\textbf{}
- YAML中的
\\textbf{}
- 使字母加粗
- YAML中的
\fontsize{14pt}{3pt}\\selectfont
在YAML中\\fontsize{14pt}{3pt}\\selectfont
- 使用3pt换行符生成字母14pt
keep_tex:true
MWE
输出
一旦您通过了自定义PDF输出的某一点,您使用的是Latex,而不是Rmarkdown,因此您最好看看tex.stackexchange上的问题。com@AlejandroCarrera我有一个答案,这不需要你编辑
.tex
文件。@马吕斯是对的:这更像是一个乳胶而不是一个标记问题。你可以在你想要的任何地方使用LateX命令,当你编织一个PDF时,只需要转义一些字符。
---
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.