像align
和gather
这样的环境显然是为在LaTeX文本段落中使用而设计的,因为文档文本和数学环境开头之间的两个换行符插入了相当于两个段落的垂直空白。然而,Markdown总是在其上的文本下面两行启动任何LaTeX环境,即使您在markdown代码/文本的同一行开始环境,即使您在它前面放了2个空格以便添加一个换行符。由于markdown没有原生的多行数学显示,这造成了一个两难境地。
在环境之前运行\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*}
发布于 2017-12-27 14:47:16
在这种情况下,最好的做法是使用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
-related显示路线执行此操作。
https://stackoverflow.com/questions/47981566
复制相似问题