碰巧的是,LaTeX 为了垂直填充页面,会在方程式环境(和其他垂直空间)周围添加额外的空格。现在假设我有一个定理环境(使用 amsthm),它以一个方程式结尾,例如:
\begin{theorem}
It holds
\begin{equation}
2+2=4
\end{equation}
\end{theorem}
\begin{proof}
Straightforward.
\end{proof}
假设这段代码呈现在被 LaTeX 垂直拉伸的页面中。那么 LaTeX 只会在公式之前添加额外的垂直空间,而不会在公式之后添加,这看起来很丑陋。问题出在哪里?
编辑:只有当我使用自定义定理样式时才会出现此问题。所以问题是:我应该如何使用命令 \newtheoremstyle 才能正确处理间距?例如
\newtheoremstyle{myplain} {2cm}% ⟨Space above⟩
{2cm}% ⟨Space below⟩
{\itshape}% ⟨Body font⟩
{}% ⟨Indent amount⟩
{\bfseries}% ⟨Theorem head font⟩
{.}% ⟨Punctuation after theorem head⟩
{.5em}% ⟨Space after theorem head⟩2
{}% ⟨Theorem head spec (can be left empty, meaning ‘normal’)⟩
给出了上述问题,而
\newtheoremstyle{myplain} {\topsep}% ⟨Space above⟩
{\topsep}% ⟨Space below⟩
{\itshape}% ⟨Body font⟩
{}% ⟨Indent amount⟩
{\bfseries}% ⟨Theorem head font⟩
{.}% ⟨Punctuation after theorem head⟩
{.5em}% ⟨Space after theorem head⟩2
{}% ⟨Theorem head spec (can be left empty, meaning ‘normal’)⟩
才不是。
EDIT2:一个工作示例:
\documentclass[a4paper]{amsart}
\usepackage{amsthm}
\newtheoremstyle{myplain} {2cm}% ⟨Space above⟩
{2cm}% ⟨Space below⟩
{\itshape}% ⟨Body font⟩
{}% ⟨Indent amount⟩
{\bfseries}% ⟨Theorem head font⟩
{.}% ⟨Punctuation after theorem head⟩
{.5em}% ⟨Space after theorem head⟩2
{}% ⟨Theorem head spec (can be left empty, meaning ‘normal’)⟩
\theoremstyle{myplain}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}
It holds
\begin{equation}
2+2=4
\end{equation}
\end{theorem}
\begin{proof}
Straightforward.
\end{proof}
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\begin{gather}
2\\
2\\
2\\
\end{gather}
\end{document}
答案1
您观察到了一些有趣的行为!您可以将其视为 LaTeX 内核中的一种错误。那么这里发生了什么?显示屏下方有一些垂直空间(\belowdisplayskip
)和定理之后(\thm@postskip
的2cm
现在 LaTeX 的设计使得它不会添加和但较大的一个这两个垂直空间(这很好)。
问题在于如何选择较大的空间。这是在 LaTeX 的 中完成的\@xaddvskip
,它只比较空间的“自然长度”分量,而不比较可用的拉伸和收缩。在您的例子中,\belowdisplayskip
是4.19998pt plus 4.19998pt
,\thm@postskip
是56.9055pt
。通常后者较大,但您遇到的情况是空间被拉伸到通常允许的 128 倍左右(这就是您收到警告的原因Underfull \vbox
!)。因此,\belowdisplayskip
实际上是两个空间中较大的一个,但只在显示下方\@xaddvskip
添加了较小的一个\thm@postskip
。2cm
我认为一个好的解决方案是与最大限度两个垂直空间的,含义如下:使用自然和拉伸分量的最大值,以及收缩分量的最小值。我\@xaddvskip
在下面的代码中实现了适当的修改。在左侧,您可以看到代码的输出,在右侧,可以看到修改后的输出\@xaddvskip
:
您可以看到,在改进的(右)版本中,等式下方的空间比上方的空间要多一点。原因是等式上方\abovedisplayskip
使用了( ),而和4.19998pt plus 4.19998pt
的最大值下方的空间为,等于,因此比上方的空间多一点。这很好,因为您想要在定理下方留出更多空间!\belowdisplayskip
\thm@postskip
56.9055pt plus 4.19998pt
52.7pt
请注意,以下代码仅仅是一个概念证明,如果涉及无限拉伸或收缩组件,它就无法正常工作。
\documentclass[a4paper]{amsart}
\makeatletter
\def\@xaddvskip{%
\ifdim\lastskip<\@tempskipb
\edef\last@stretch{\the\gluestretch\lastskip}
\edef\last@shrink{\the\glueshrink\lastskip}
\edef\next@stretch{\the\gluestretch\@tempskipb}
\edef\next@shrink{\the\glueshrink\@tempskipb}
\vskip-\lastskip
\dimen@=\@tempskipb
\vskip\dimen@ plus
\ifdim \last@stretch > \next@stretch
\last@stretch
\else
\next@stretch
\fi
minus
\ifdim \last@shrink < \next@shrink
\last@shrink
\else
\next@shrink
\fi
\else
\ifdim\@tempskipb<\z@
\ifdim\lastskip<\z@
\else
\advance\@tempskipb\lastskip
\vskip-\lastskip
\vskip \@tempskipb
\fi
\fi
\fi}
\makeatother
\usepackage{amsthm}
\newtheoremstyle{myplain} {2cm}% ⟨Space above⟩
{2cm}% ⟨Space below⟩
{\itshape}% ⟨Body font⟩
{}% ⟨Indent amount⟩
{\bfseries}% ⟨Theorem head font⟩
{.}% ⟨Punctuation after theorem head⟩
{.5em}% ⟨Space after theorem head⟩2
{}% ⟨Theorem head spec (can be left empty, meaning ‘normal’)⟩
\theoremstyle{myplain}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}
It holds
\begin{equation}
2+2=4
\end{equation}
\end{theorem}
\begin{proof}
Straightforward.
\end{proof}
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip \bigskip
\begin{gather}
2\\
2\\
2\\
\end{gather}
\end{document}
只是为了完整性,这里是我原来的 e-TeX-free 实现\getstretch
和\getshrink
:
\begingroup
\catcode`P=12
\catcode`L=12
\catcode`U=12
\catcode`S=12
\catcode`M=12
\catcode`I=12
\catcode`N=12
\catcode`T=12
\lowercase{
\def\x{%
\def\getstretch##1{\expandafter\get@stretch\the##1PLUS 0PT\endmarker}
\def\get@stretch##1PLUS##2PT##3\endmarker{##2}
\def\getshrink##1{\expandafter\get@shrink\the##1MINUS 0PT\endmarker}
\def\get@shrink##1MINUS##2PT##3\endmarker{##2}
}}
\expandafter\endgroup\x
答案2
问题是你的“上方空间”和“下方空间”没有灵活性,而\topsep
有。增加一些灵活性:
\documentclass[a4paper]{amsart}
\usepackage{amsthm}
\newtheoremstyle{myplain}
{2cm plus 1cm minus 0.5cm}% ⟨Space above⟩
{2cm plus 1cm minus 0.5cm}% ⟨Space below⟩
{\itshape}% ⟨Body font⟩
{}% ⟨Indent amount⟩
{\bfseries}% ⟨Theorem head font⟩
{.}% ⟨Punctuation after theorem head⟩
{.5em}% ⟨Space after theorem head⟩2
{}% ⟨Theorem head spec (can be left empty, meaning ‘normal’)⟩
\theoremstyle{myplain}
\newtheorem{theorem}{Theorem}
\begin{document}
Some text above.
\begin{theorem}
It holds
\begin{equation}
2+2=4
\end{equation}
\end{theorem}
\begin{proof}
Straightforward.
\end{proof}
some text for stretching
\pagebreak
\end{document}