r markdown 中的 4 级和 5 级标题渲染问题

问题描述 投票:0回答:2

Rmarkdown
中的4级和5级标题在pdf文件中渲染后不会创建新行。我只是想知道如何解决这个问题。
用于生成 pdf 的 R markdown 代码

上面显示的代码的 pdf 输出

r r-markdown
2个回答
4
投票

这有点骇人听闻,但似乎有效:

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

0
投票

一个合理的方法是在文档中添加 LaTeX 序言,您可以在其中覆盖第 4 级(即段落)和第 5 级(即子段落)标题的标题格式定义:

标题.tex

首先将 header.tex 文件与 Test.Rmd 文档一起保存,其中包含以下内容:

\usepackage{titlesec}

\titleformat{\paragraph}[display]
{\normalfont\normalsize\bfseries}{\paragraphtitlename \theparagraph}{1em}{}

\titleformat{\subparagraph}[display]
{\normalfont\normalsize\bfseries}{\subparagraphtitlename \thesubparagraph}{1em}{}

测试.Rmd

然后编辑您的 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

编织后,您应该有一个具有所需间距的 PDF。

© www.soinside.com 2019 - 2024. All rights reserved.