像align
和gather
这样的环境非常清晰地设计用于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*}
在这种情况下,您可以做的最好的事情是使用\vspace{-\baselineskip}
在每个特定环境的开头自动插入etoolbox
package:
---
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
相关的显示对齐执行此操作。