这有点骇人听闻,但似乎有效:
---
title: "Untitled"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
### 3rd-level heading
Content 3
#### 4th-level heading
\hspace{-2.5em} Content 4
##### 5th-level heading
\hspace{-2.5em} Content 5
一个合理的方法是在文档中添加 LaTeX 序言,您可以在其中覆盖第 4 级(即段落)和第 5 级(即子段落)标题的标题格式定义:
首先将 header.tex 文件与 Test.Rmd 文档一起保存,其中包含以下内容:
\usepackage{titlesec}
\titleformat{\paragraph}[display]
{\normalfont\normalsize\bfseries}{\paragraphtitlename \theparagraph}{1em}{}
\titleformat{\subparagraph}[display]
{\normalfont\normalsize\bfseries}{\subparagraphtitlename \thesubparagraph}{1em}{}
然后编辑您的 Test.Rmd 以将以下内容添加到您的 YAML:
---
title: "Test"
output:
pdf_document:
includes:
in_header: header.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
### 3rd-level heading
Content 3
#### 4th-level heading
Content 4
##### 5th-level heading
Content 5
编织后,您应该有一个具有所需间距的 PDF。