有什么方法可以让R Markdown将LaTeX环境放在新的段落中?

时间:2017-12-26 17:07:11

标签: latex r-markdown multiline

aligngather这样的环境非常清晰,可以在LaTeX文本的一段中使用,因为文档文本和数学环境的开头之间的两个换行符会插入一个令人震惊的两段值得垂直的白色空间。但是,Markdown总是在其上方的文本下面两行开始任何LaTeX环境,即使你在markdown代码/文本的同一行开始环境,即使你在它之前放置2个空格以便添加一个单线休息。由于没有多线数学差异原生于降价,这就构成了两难选择。

在环境补偿之前运行\vspace{-\baselineskip},但当然最好只告诉markdown不要在第一时间插入换行符。那可能吗?如果没有,那么在每个对齐(和/或对齐*,聚集,聚集*等)环境开始之前自动运行\vspace{-\baselineskip}的最简单方法是什么?

MWE:

---
output:
  pdf_document:
    keep_tex: 1
---

The following environment will get marked up with an extra two lines between it and 
this text, putting it on a new paragraph and creating a lot of whitespace above it, 
whether or not there's any line breaks in the markdown code:
\begin{gather*}
A \\ B
\end{gather*}

This can of course be hackily corrected by subtracting vertical space: 
\vspace{-\baselineskip} \begin{gather*}
A \\ B
\end{gather*}

1 个答案:

答案 0 :(得分:0)

在这种情况下,您可以做的最好的事情是使用etoolbox package在每个特定环境的开头自动插入\vspace{-\baselineskip}

---
output:
  pdf_document:
    keep_tex: 1
header-includes:
  - \usepackage{etoolbox}
  - \AtBeginEnvironment{gather}{\vspace{-\baselineskip}}
  - \AtBeginEnvironment{gather*}{\vspace{-\baselineskip}}
---

The following environment will get marked up with an extra two lines between it and 
this text, putting it on a new paragraph and creating a lot of whitespace above it, 
whether or not there's any line breaks in the markdown code:
\begin{gather*}
A \\ B
\end{gather*}

This can of course be hackily corrected by subtracting vertical space: 
\begin{gather*}
A \\ B
\end{gather*}

然而,这并不是最佳的,因为环境插入的间隙取决于结束前一段的文本量。由于Pandoc的处理,金额总是相同的(\abovedisplayskip),所以使用它可能“更好”

header-includes:
  - \usepackage{etoolbox}
  - \AtBeginEnvironment{gather}{\vspace{\dimexpr-\baselineskip-\abovedisplayskip}}
  - \AtBeginEnvironment{gather*}{\vspace{\dimexpr-\baselineskip-\abovedisplayskip}}

您必须为所有与amsmath相关的显示对齐执行此操作。