The level 4 and 5 headers in Rmarkdown
does not create a new line after they are rendered in the pdf file. I am just wondering how I could fix this issue.
The R markdown codes to generate pdf
The pdf output from the code shown above
The level 4 and 5 headers in Rmarkdown
does not create a new line after they are rendered in the pdf file. I am just wondering how I could fix this issue.
The R markdown codes to generate pdf
The pdf output from the code shown above
This is hackish, but it seems to work:
---
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
A reasonable approach is to add a LaTeX preamble to your document where you override the title format definitions of Level 4 (i.e., paragraph) and Level 5 (i.e., subparagraph) headers:
First save a header.tex file alongside your Test.Rmd document with the following contents:
\usepackage{titlesec}
\titleformat{\paragraph}[display]
{\normalfont\normalsize\bfseries}{\paragraphtitlename \theparagraph}{1em}{}
\titleformat{\subparagraph}[display]
{\normalfont\normalsize\bfseries}{\subparagraphtitlename \thesubparagraph}{1em}{}
Then edit your Test.Rmd to add the following to your 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
After knitting, you should have a PDF with the desired spacing.
© 2022 - 2024 — McMap. All rights reserved.
<br />
. For future add your code as chunk in your question not as a image. Make it as easy as possible for people to help – Specious