更改数学显示模式之前和之后的垂直间距

更改数学显示模式之前和之后的垂直间距

我正在编写双倍行距文档,但我不想在数学显示环境之间留出过多的间距。对于我可以使用etoolbox和说的代码列表等内容\AtBeginEnvironment{minted}{\setstretch{1}},有没有办法修改数学显示前/后的拉伸?

\documentclass{article}
\usepackage{lipsum}
\usepackage[margin=0.5in]{geometry}

\usepackage{setspace}
\setstretch{2}

% kind of does the right thing, but only at the bottom...
% \everydisplay{\vspace*{-1em}}

\usepackage{amsmath}

% i think this is only for align?
% \belowdisplayskip=0pt

% this also doesn't work, just for array?
% \setlength{\jot}{-1ex}

\usepackage{etoolbox}
% is math / amsmath an environment?
\AtBeginEnvironment{math}{\setstretch{1}}
\AfterEndEnvironment{math}{\setstretch{2}}

\begin{document}
    \lipsum[1]

    % desired effect without manual every time
    % \setstretch{1}
    $$
        ax + by + cz + d = 0
    $$
    % not really even working
    % \setstretch{2}\vspace*{-2em}

    \lipsum[2]
\end{document}

我想在全球范围内执行此操作,摆脱红色矩形表示的间距

在此处输入图片描述

我觉得这肯定是重复的,但我找不到任何可以工作的东西 :/ 如果这很重要的话,上面的代码是 pdftex,但我用 xetex 编写。我认为这对这个问题没有影响,但可能会。

答案1

您的输入有两个错误:

您可以使用nodisplayskipstretch选项setspace,将间距减小到可接受的程度。

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{amsmath}
\usepackage[nodisplayskipstretch]{setspace}

\usepackage{lipsum}

\setstretch{2}

\begin{document}

\lipsum*[1]% no \par or blank line before a math display
\[% not $$
ax + by + cz + d = 0
\]% and no blank line after a math display, generally.
\lipsum[2]

\end{document}

在此处输入图片描述

为了进行比较,以下是没有该选项的输出

在此处输入图片描述

还有你用空白行得到的$$

在此处输入图片描述

我还添加了输出\doublespacing(人们普遍认为双倍行距意味着\setstretch{2},这是不正确的)。

在此处输入图片描述

答案2

解决方案是修改以下长度:

\abovedisplayskip\belowdisplayskip\abovedisplayshortskip\belowdisplayshortskip

示例显示了发生了什么:

\documentclass{article}

\usepackage{lipsum}

\begin{document}

{\Large Normal}

test text that has to be long enought to go over the formula
\[f(x)=3\]
test continue text that will be long enought too

test text that is short
\begin{equation}
  x=f(y)
\end{equation}
test continue text that will be long enought too

{\Large All Zero}

\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}


test text that has to be long enought to go over the formula
\[f(x)=3\]
test continue text that will be long enought too

test text that is short
\begin{equation}
  x=f(y)
\end{equation}
test continue text that will be long enought too

{\Large normal 10pt short 5pt}

\setlength{\abovedisplayskip}{10pt}
\setlength{\belowdisplayskip}{10pt}
\setlength{\abovedisplayshortskip}{5pt}
\setlength{\belowdisplayshortskip}{5pt}


test text that has to be long enought to go over the formula
\[f(x)=3\]
test continue text that will be long enought too


\lipsum[3]

test text that is short
\begin{equation}
  x=f(y)
\end{equation}
test continue text that will be long enought too

\end{document}

在 OP 的第一条评论后进行编辑:

您可以将此代码添加到您的序言中。每次字体更改都将包含一个\selectfont命令(隐藏或不隐藏),因此,它在字体更改后也会保留(我认为是大小和形状)。

\def\mycommand{\setlength{\abovedisplayskip}{0pt}%
\setlength{\belowdisplayskip}{0pt}%
\setlength{\abovedisplayshortskip}{0pt}%
\setlength{\belowdisplayshortskip}{0pt}}

\let\oldselectfont\selectfont
\def\selectfont{\oldselectfont\mycommand}

\mycommand

来源:http://latex.org/forum/viewtopic.php?t=4993来自 Stefan Kottwitz。

输出:

在此处输入图片描述

PS:在不需要将数学运算与文本足够清晰地分开的情况下,更多地使用短跳过。(amsmath包为这些跳过使用了更多选项。有关更多信息,请参见此处:abovedisplayskip 与 abovedisplayshortskip

PS2:参见@dalief 的评论

相关内容