R Markdown 中的 4 级标题问题
Level 4 Heading issue in R Markdown
当我对 4 级标题使用 #### 时,pdf(latex) 中的输出不会在段落开始前留下一行 space。例如,
#### Heading 4
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book.
仅以 pdf(latex) 格式输出如下所示
标题 4 Lorem Ipsum 只是印刷和排版行业的虚拟文本。自 1500 年代以来,Lorem Ipsum 一直是行业的标准虚拟文本,当时一位不知名的印刷商拿走了一个字体厨房,并把它加在一起制作了一本字体样本书。
我到处都读到 r markdown 允许 1-6 # 作为标题,所以我想弄清楚我在这里做错了什么。
我还想我可以使用 \subsubsubsubsection 而不是 #### 作为标题,但这给了我一个错误。
这本质上是一个 LaTeX 风格的问题,而不是 (r)markdown-specific 问题。如果添加 YAML header
---
output:
pdf_document:
keep_tex: true
---
到您的文档(或将这些行添加到现有的 YAML header),生成的 LaTeX 文件将被保留;然后您可以查看 LaTeX 文件以查看生成的内容是:
\paragraph{Heading 4}\label{heading-4}
Lorem Ipsum ...
问题是 LaTeX 中的默认段落样式不包含换行符。一旦您知道这是怎么回事,您可以搜索类似 this LaTeX incantation from tex.stackexchange.com 的内容,创建一个包含
的 parahdr.tex
文件
\usepackage{titlesec}
\titleformat{\paragraph}
{\normalfont\bfseries}
{}
{0pt}
{}
并根据 "advanced customization" documentation for PDF output from the rmarkdown package:
将其合并到您的 YAML header
---
output:
pdf_document:
keep_tex: true
includes:
in_header: parahdr.tex
---
请参阅 Mico 对以下问题的回答:
将此代码添加到您的 tex 头文件中,应该这样做:
\documentclass{article}
\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
{-2.5ex\@plus -1ex \@minus -.25ex}%
{1.25ex \@plus .25ex}%
{\normalfont\normalsize\bfseries}}
\makeatother
\setcounter{secnumdepth}{4} % how many sectioning levels to assign numbers to
当我对 4 级标题使用 #### 时,pdf(latex) 中的输出不会在段落开始前留下一行 space。例如,
#### Heading 4
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book.
仅以 pdf(latex) 格式输出如下所示
标题 4 Lorem Ipsum 只是印刷和排版行业的虚拟文本。自 1500 年代以来,Lorem Ipsum 一直是行业的标准虚拟文本,当时一位不知名的印刷商拿走了一个字体厨房,并把它加在一起制作了一本字体样本书。
我到处都读到 r markdown 允许 1-6 # 作为标题,所以我想弄清楚我在这里做错了什么。
我还想我可以使用 \subsubsubsubsection 而不是 #### 作为标题,但这给了我一个错误。
这本质上是一个 LaTeX 风格的问题,而不是 (r)markdown-specific 问题。如果添加 YAML header
---
output:
pdf_document:
keep_tex: true
---
到您的文档(或将这些行添加到现有的 YAML header),生成的 LaTeX 文件将被保留;然后您可以查看 LaTeX 文件以查看生成的内容是:
\paragraph{Heading 4}\label{heading-4}
Lorem Ipsum ...
问题是 LaTeX 中的默认段落样式不包含换行符。一旦您知道这是怎么回事,您可以搜索类似 this LaTeX incantation from tex.stackexchange.com 的内容,创建一个包含
的parahdr.tex
文件
\usepackage{titlesec}
\titleformat{\paragraph}
{\normalfont\bfseries}
{}
{0pt}
{}
并根据 "advanced customization" documentation for PDF output from the rmarkdown package:
将其合并到您的 YAML header---
output:
pdf_document:
keep_tex: true
includes:
in_header: parahdr.tex
---
请参阅 Mico 对以下问题的回答:
将此代码添加到您的 tex 头文件中,应该这样做:
\documentclass{article}
\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
{-2.5ex\@plus -1ex \@minus -.25ex}%
{1.25ex \@plus .25ex}%
{\normalfont\normalsize\bfseries}}
\makeatother
\setcounter{secnumdepth}{4} % how many sectioning levels to assign numbers to