Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Rmarkdown自定义标题?_R_Pdf_Pdf Generation_R Markdown - Fatal编程技术网

如何使用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{}
    • 使字母斜体
  • \textbf{}
    • YAML中的
      \\textbf{}
    • 使字母加粗
  • \fontsize{14pt}{3pt}\\selectfont
    • \\fontsize{14pt}{3pt}\\selectfont
      在YAML中
    • 使用3pt换行符生成字母14pt
正如@Marius所建议的,除了简单的标记语法之外,您可能还需要进一步自定义输出。因此,最好为这种情况设置
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.