我尝试使用以下方法将字幕与纯文本分开two空格处。
我的 .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)
但最终的输出总是这样的:
纯文本
第一个字幕第一个字幕后有 2 个空格
library(lubridate)
第二个副标题纯文本(第二个字幕之后也有 2 个空格)
只有当我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
常见的 LaTex 层次结构为节-小节-小节-段落-小段落。
所以 Rmarkdown 格式####
由 LaTeX 格式定义\paragraph{}
。在标准 LaTeX 样式中,段落不会换行。这是一个经典问题,有几种解决方法(例如here https://tex.stackexchange.com/questions/5035/paragraph-style-how-to-force-line-break-paragraph-make-paragraph-a-he or there https://tex.stackexchange.com/questions/32160/new-line-after-paragraph),这里我将使用that one https://latex.org/forum/viewtopic.php?t=1383。对于该解决方案,我们需要在 LaTeX 标头中包含以下代码:
\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 文档中,在标题中 https://bookdown.org/yihui/rmarkdown/pdf-document.html我们可以包含对该 LaTeX 文件的引用:
---
title: "My Rmarkdown document"
author: "me"
date: "9/19/2020"
output:
pdf_document:
includes:
in_header: reformat_paragraph.tex
---
那应该有效!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)