字幕与文字混合

Subtitles mixing with text

我尝试使用 two 空白 space.
将字幕与纯文本分开 我的 .Rmd 文件的第一部分看起来像这样


---
title: 'Script de Limpieza: errores de digitalizacion y division de base madre'
author: "Leonardo Doig & Karen Lau"
date: "10/9/2020"
output:
  html_document: default
  word_document: default
  pdf_document: default
---


{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)


some random words should be here

#### First subtitle  

there are 2 blank spaces after the first subtitle


{r message=FALSE}
library(lubridate)

#### Second Subtitle   

plain text (after the second subtitle there are 2 blanks spaces too)

但最终输出总是这样:

plain text
First subtitle there are 2 blank spaces after the first subtitle

library(lubridate)

Second Subtitle plain text (after the second subtitle there are 2 blanks spaces too)


只有当我 Knit 我的 .Rmd 文件到 .pdf 时才会发生。当我 Knit 到 .html 所有这些乱七八糟的字幕和纯文本似乎没问题。

此行为的原因是此降价:

# Level 1
Text 1
## Level 2
Text 2
### Level 3
Text 3
#### Level 4
Text 4
##### Level 5

转换为 LaTeX 代码:

\hypertarget{level-1}{%
\section{Level 1}\label{level-1}}

Text 1

\hypertarget{level-2}{%
\subsection{Level 2}\label{level-2}}

Text 2

\hypertarget{level-3}{%
\subsubsection{Level 3}\label{level-3}}

Text 3

\hypertarget{level-4}{%
\paragraph{Level 4}\label{level-4}}

Text 4

\hypertarget{level-5}{%
\subparagraph{Level 5}\label{level-5}}

Text 5

使用 section-subsection-subsubsection-paragraph-subparagraph 的常见 LaTex 层次结构。

因此 #### 的 Rmarkdown 格式是由 \paragraph{} 的 LaTeX 格式定义的。在标准的 LaTeX 样式中,段落没有换行符。这是一个经典问题,有几种解决方法(例如 here or there), Here I'll use that one。对于该解决方案,我们需要将此代码包含在 LaTeX header:

\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
  {-3.25ex\@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\normalfont\normalsize\bfseries}}
\makeatother

让我们将该代码单独保存到一个文件中,比如说 reformat_paragraph.tex。现在在我们的 Rmarkdown 文档中,in the header 我们可以包含对该 LaTeX 文件的引用:

---
title: "My Rmarkdown document"
author: "me"
date: "9/19/2020"
output:
  pdf_document:
    includes:
      in_header: reformat_paragraph.tex
---

那应该行得通!