如何在“alignat”和“align”环境中全局减少或删除行之间的垂直间距?

如何在“alignat”和“align”环境中全局减少或删除行之间的垂直间距?

首先,MWE 及其输出如下。

\documentclass{article}
\usepackage{amsfonts,amssymb,amsmath}

\begin{document}
An example in `alignat'
\begin{alignat*}{2}
x&=3&\hspace*{1em}&why\\
&=2+1&&so\\
x&=3&\hspace*{1em}&why\\
&=2+1&&so\\
x&=3&\hspace*{1em}&why\\
&=2+1&&so.
\end{alignat*}
and an example in `align'
\begin{align*}
x&=3\\
&=2+1\\
x&=3\\
&=2+1\\
x&=3\\
&=2+1.
\end{align*}
and an example in `array'
\[
\begin{array}{rl}
x&=3\\
&=2+1\\
x&=3\\
&=2+1\\
x&=3\\
&=2+1.
\end{array}
\]

\end{document}

在此处输入图片描述

如你所见,和环境中的x=3和等行之间的垂直间距比环境中的要大。然后2+1alignatalignarray如何全局减少或删除alignatalign环境中行之间的垂直空格?

答案1

详细阐述@daleif 的评论,我提出以下内容并希望这对您来说足够接近。

结果

\documentclass{article}
\usepackage{amsmath}

%%%Set some lengths to zero.
\setlength{\jot}{0pt}
%\setlength{\abovedisplayskip}{0pt}
%\setlength{\belowdisplayskip}{0pt}
%\setlength{\abovedisplayshortskip}{0pt}
%\setlength{\belowdisplayshortskip}{0pt}

% Save all variants into boxes to measure their heights.
\newsavebox{\alignatbox}
\savebox{\alignatbox}{%
   \begin{minipage}{\linewidth}%
      \begin{alignat*}{1}%
         x&=3\\&=2+1\\x&=3\\&=2+1\\x&=3\\&=2+1.%
      \end{alignat*}%
   \end{minipage}
}
\newsavebox{\alignbox}
\savebox{\alignbox}{%
   \begin{minipage}{\linewidth}%
      \begin{align*}{2}%
         x&=3\\&=2+1\\x&=3\\&=2+1\\x&=3\\&=2+1.%
      \end{align*}%
   \end{minipage}
}
\newsavebox{\arraybox}
\savebox{\arraybox}{%
   \begin{minipage}{\linewidth}%
      \[%
      \begin{array}{rlll}%
         x&=3\\&=2+1\\x&=3\\&=2+1\\x&=3\\&=2+1.%
      \end{array}%
      \]
   \end{minipage}
}

\begin{document}
   \paragraph{An example in `alignat'.}
   height: \the\ht\alignatbox\par
   \usebox{\alignatbox}
   
   \paragraph{An example in `align'.}
   height: \the\ht\alignbox\par
   \usebox{\alignbox}
   
   \paragraph{An example in `array'.}
   height: \the\ht\arraybox\par
   \usebox{\arraybox}
\end{document}

相关内容