【问题标题】:Level 4 Heading issue in R MarkdownR Markdown 中的 4 级标题问题
【发布时间】:2016-01-13 01:52:09
【问题描述】:

当我将#### 用于第 4 级标题时,pdf(latex) 中的输出不会在段落开始前留出行间距。例如,

#### 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 而不是 #### 作为标题,但这给了我一个错误。

【问题讨论】:

    标签: r latex knitr r-markdown pdflatex


    【解决方案1】:

    查看 Mico 对以下问题的回答:

    https://tex.stackexchange.com/questions/60209/how-to-add-an-extra-level-of-sections-with-headings-below-subsubsection

    将此代码添加到您的 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
    

    【讨论】:

    • 我做了类似的事情,但差不多就是这样。
    • 你做了什么?它会帮助我。
    【解决方案2】:

    这本质上是一个 LaTeX 风格的问题,而不是一个 (r)markdown 特定的问题。如果添加 YAML 标头

    ---
    output:
       pdf_document:
          keep_tex: true
    ---
    

    到您的文档(或将这些行添加到现有的 YAML 标头),生成的 LaTeX 文件将被保留;然后您可以查看 LaTeX 文件以查看生成的内容是:

    \paragraph{标题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 标头中:

    ---
    output:
       pdf_document:
          keep_tex: true
          includes: 
              in_header: parahdr.tex
    ---
    

    【讨论】:

    • 感谢您的解决方案。它确实有助于在新行上开始段落,但标题上没有节编号。所以,这很像用粗体写 Heading4。查看乳胶代码,问题是在第 3 级标题之后,乳胶认为任何其他标题都是段落标题,因此解决了我的问题 :)
    猜你喜欢
    • 1970-01-01
    • 2017-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多