【问题标题】:Subtitles mixing with text字幕与文字混合
【发布时间】:2020-09-19 04:23:00
【问题描述】:

我尝试使用 两个 空格将我的字幕与纯文本分开。
我的 .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个空格)


仅当我将 .Rmd 文件编织为 .pdf 时才会发生这种情况。当我编织到 .html 时,所有这些混乱的字幕和纯文本似乎都没问题。

【问题讨论】:

  • 你能给出一个完整的可重现的例子吗?我没有这个问题。
  • 如果您将帖子添加到重现问题所需的最小降价之上,这将对其他人有所帮助。
  • 我在本地运行此程序,将 knitr::opts_chunk$set(echo = TRUE) 放入 r 块中,并创建了一个“随机”r 块,但无法重现您的问题。请将代码放入您的帖子中的一个块中,有人可以剪切/粘贴以重现。在目前的状态下,这不是一个可重现的问题。当我运行我认为您打算为您的代码执行的操作时,纯文本 被放在自己的行上(这是您想要的)。我会编辑您的问题以澄清我的意思,但我使用的代码不会重现该问题(这就是我要求您更新问题的原因)。
  • 我投票结束这个问题,因为目前这个问题不可重现。代码示例应该在一个重现问题的代码块中;它不在一个代码块中,当我把它放在一起时,它不会为我重现问题
  • 所以我不确定你为什么不能重现我遇到的问题(?)但这是我最后一次尝试

标签: r r-markdown knitr


【解决方案1】:

这种行为的原因是这个markdown:

# 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 样式中,段落没有换行符。这是一个经典问题,有几种解决方法(例如herethere),这里我将使用that one。对于该解决方案,我们需要在 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 文档中,in the header 我们可以包含对该 LaTeX 文件的引用:

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

这应该行得通!

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-19
  • 2012-01-24
  • 2018-06-13
  • 1970-01-01
相关资源
最近更新 更多