align
当线条中有分数时,环境内的默认垂直间距看起来非常紧。
我知道可以进行三种手动调整:
- 调整值
\jot
。 - 通过 在每一行上必要时添加垂直空格
\\[<amount>]
。 - 使用
spreadlines
mathtools 包中的环境。
解决方案 1 和 3 甚至在不需要它们的行之间添加了垂直空间,因此如果方程组中没有分数的行(以及有分数的行),则间距就不太正确。
问题:
是否没有某种自动化解决方案来始终在一行的底部和下一行的顶部之间留出适当的垂直空间?
参考:
代码:
\documentclass{article}
\usepackage{mathtools}% includes amsmath
\begin{document}
\begin{minipage}[t]{0.20\linewidth}
\textbf{Nice}
\begin{align*}
x &= 73 \times 2\\
&= 146
\end{align*}
\end{minipage}%
%
\begin{minipage}[t]{0.25\linewidth}
\textbf{Not so nice}
\begin{align*}
x &= \frac{146}{10}\\
&= \frac{73}{5}
\end{align*}
\end{minipage}%
\bigskip\par\noindent
\textbf{Manual Tweak Options:}
\medskip\par\noindent
\begin{minipage}[t]{0.25\linewidth}
\textbf{Tweak jot}
\setlength{\jot}{8pt}% tweak
\begin{align*}
x &= \frac{146}{10}\\
&= \frac{73}{5}
\end{align*}
\end{minipage}%
%
\begin{minipage}[t]{0.30\linewidth}
\textbf{Add vertical space}
\begin{align*}
x &= \frac{146}{10}\\[5pt]% tweak
&= \frac{73}{5}
\end{align*}
\end{minipage}%
%
\begin{minipage}[t]{0.30\linewidth}
\textbf{spreadlines}
\begin{spreadlines}{0.8em}% tweak
\begin{align*}
x &= \frac{146}{10}\\
&= \frac{73}{5}
\end{align*}
\end{spreadlines}
\end{minipage}%
\end{document}
测试建议的修复方案:
我测试了建议的修复方案,它似乎修复了“不太好”的部分:
不确定我是否喜欢顶部的额外垂直空间。
但此外,它还在不需要的地方添加了空格,就像之前“很好”的部分一样:
在需要手动调整的情况下,可能不应延长调整时间(或者仅在间距不够时延长调整时间)。就我个人而言,没有这个也可以工作,但也许有一种禁用它的方法是不错的:
代码:
\documentclass{article}
\usepackage{mathtools}% includes amsmath
\begin{document}
\par\noindent
%---------------------------------------- Oringally "Nice"
\begin{minipage}[t]{0.30\linewidth}
\textbf{Nice}
\begin{align*}
x &= 73 \times 2\\
&= 146
\end{align*}
\end{minipage}%
%
\begin{minipage}[t]{0.30\linewidth}
\makeatletter
\def\align@preamble{%
&\hfil
\setboxz@h{\@lign$\m@th\displaystyle{##}$}%
\ifdim\ht\z@<\ht\strutbox@
\ht\z@\ht\strutbox@
\dimen@\ht\strutbox@
\advance\[email protected]
\ht\strutbox@\dimen@
\fi
\strut@
\ifmeasuring@\savefieldlength@\fi
\set@field
\tabskip\z@skip
&\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}%
\ifdim\ht\z@<\ht\strutbox@
\ht\z@\ht\strutbox@
\dimen@\ht\strutbox@
\advance\[email protected]
\ht\strutbox@\dimen@
\fi
\strut@
\ifmeasuring@\savefieldlength@\fi
\set@field
\hfil
\tabskip\alignsep@
}%
\makeatother
%
%
\textbf{With 2012-05-09 fix:}
\begin{align*}
x &= 73 \times 2\\
&= 146
\end{align*}
\end{minipage}%
\bigskip\par\noindent
%---------------------------------------- Oringally "Not so Nice"
\begin{minipage}[t]{0.30\linewidth}
\textbf{Not so nice}
\begin{align*}
x &= \frac{146}{10}\\
&= \frac{73}{5}
\end{align*}
\end{minipage}%
%
\begin{minipage}[t]{0.30\linewidth}
\makeatletter
\def\align@preamble{%
&\hfil
\setboxz@h{\@lign$\m@th\displaystyle{##}$}%
\ifdim\ht\z@<\ht\strutbox@
\ht\z@\ht\strutbox@
\dimen@\ht\strutbox@
\advance\[email protected]
\ht\strutbox@\dimen@
\fi
\strut@
\ifmeasuring@\savefieldlength@\fi
\set@field
\tabskip\z@skip
&\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}%
\ifdim\ht\z@<\ht\strutbox@
\ht\z@\ht\strutbox@
\dimen@\ht\strutbox@
\advance\[email protected]
\ht\strutbox@\dimen@
\fi
\strut@
\ifmeasuring@\savefieldlength@\fi
\set@field
\hfil
\tabskip\alignsep@
}%
\makeatother
%
\textbf{With 2012-05-09 fix:}
\begin{align*}
x &= \frac{146}{10}\\
&= \frac{73}{5}
\end{align*}
\end{minipage}%
\bigskip\par\noindent
\textbf{Manual Tweak Options:}
\medskip\par\noindent
%---------------------------------------- Adjust \jot
\begin{minipage}[t]{0.30\linewidth}
\textbf{Tweak jot}
\setlength{\jot}{8pt}% tweak
\begin{align*}
x &= \frac{146}{10}\\
&= \frac{73}{5}
\end{align*}
\end{minipage}%
%
\begin{minipage}[t]{0.30\linewidth}
\makeatletter
\def\align@preamble{%
&\hfil
\setboxz@h{\@lign$\m@th\displaystyle{##}$}%
\ifdim\ht\z@<\ht\strutbox@
\ht\z@\ht\strutbox@
\dimen@\ht\strutbox@
\advance\[email protected]
\ht\strutbox@\dimen@
\fi
\strut@
\ifmeasuring@\savefieldlength@\fi
\set@field
\tabskip\z@skip
&\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}%
\ifdim\ht\z@<\ht\strutbox@
\ht\z@\ht\strutbox@
\dimen@\ht\strutbox@
\advance\[email protected]
\ht\strutbox@\dimen@
\fi
\strut@
\ifmeasuring@\savefieldlength@\fi
\set@field
\hfil
\tabskip\alignsep@
}%
\makeatother
%
\textbf{With 2012-05-09 fix:}
\setlength{\jot}{8pt}% tweak
\begin{align*}
x &= \frac{146}{10}\\
&= \frac{73}{5}
\end{align*}
\end{minipage}%
%
%---------------------------------------- Adding Vertical Space
\bigskip\par\noindent
\begin{minipage}[t]{0.30\linewidth}
\textbf{Add vertical space}
\begin{align*}
x &= \frac{146}{10}\\[5pt]% tweak
&= \frac{73}{5}
\end{align*}
\end{minipage}%
%
\begin{minipage}[t]{0.30\linewidth}
\makeatletter
\def\align@preamble{%
&\hfil
\setboxz@h{\@lign$\m@th\displaystyle{##}$}%
\ifdim\ht\z@<\ht\strutbox@
\ht\z@\ht\strutbox@
\dimen@\ht\strutbox@
\advance\[email protected]
\ht\strutbox@\dimen@
\fi
\strut@
\ifmeasuring@\savefieldlength@\fi
\set@field
\tabskip\z@skip
&\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}%
\ifdim\ht\z@<\ht\strutbox@
\ht\z@\ht\strutbox@
\dimen@\ht\strutbox@
\advance\[email protected]
\ht\strutbox@\dimen@
\fi
\strut@
\ifmeasuring@\savefieldlength@\fi
\set@field
\hfil
\tabskip\alignsep@
}%
\makeatother
%
\textbf{With 2012-05-09 fix:}
\begin{align*}
x &= \frac{146}{10}\\[5pt]% tweak
&= \frac{73}{5}
\end{align*}
\end{minipage}%
%---------------------------------------- Spreadlines
\bigskip\par\noindent
\begin{minipage}[t]{0.30\linewidth}
\textbf{spreadlines}
\begin{spreadlines}{0.8em}% tweak
\begin{align*}
x &= \frac{146}{10}\\
&= \frac{73}{5}
\end{align*}
\end{spreadlines}
\end{minipage}%
%
\begin{minipage}[t]{0.30\linewidth}
\makeatletter
\def\align@preamble{%
&\hfil
\setboxz@h{\@lign$\m@th\displaystyle{##}$}%
\ifdim\ht\z@<\ht\strutbox@
\ht\z@\ht\strutbox@
\dimen@\ht\strutbox@
\advance\[email protected]
\ht\strutbox@\dimen@
\fi
\strut@
\ifmeasuring@\savefieldlength@\fi
\set@field
\tabskip\z@skip
&\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}%
\ifdim\ht\z@<\ht\strutbox@
\ht\z@\ht\strutbox@
\dimen@\ht\strutbox@
\advance\[email protected]
\ht\strutbox@\dimen@
\fi
\strut@
\ifmeasuring@\savefieldlength@\fi
\set@field
\hfil
\tabskip\alignsep@
}%
\makeatother
%
\textbf{With 2012-05-09 fix:}
\begin{spreadlines}{0.8em}% tweak
\begin{align*}
x &= \frac{146}{10}\\
&= \frac{73}{5}
\end{align*}
\end{spreadlines}
\end{minipage}%
\end{document}
答案1
AMS 对齐框并测量每个单元,以便您可以检查单元高度是否大于支柱,您可以局部增加支柱高度。
代码已更新以使用>
而不是<
因此它会打开大条目而不是小条目:-) 也不会在第一行执行任何操作以避免在显示屏上方添加空间。
\documentclass{article}
\usepackage{mathtools}% includes amsmath
\makeatletter
\newlength\minalignvsep
\def\align@preamble{%
&\hfil
\setboxz@h{\@lign$\m@th\displaystyle{##}$}%
\ifnum\row@>\@ne
\ifdim\ht\z@>\ht\strutbox@
\dimen@\ht\z@
\advance\dimen@\minalignvsep
\ht\strutbox\dimen@
\fi\fi
\strut@
\ifmeasuring@\savefieldlength@\fi
\set@field
\tabskip\z@skip
&\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}%
\ifnum\row@>\@ne
\ifdim\ht\z@>\ht\strutbox@
\dimen@\ht\z@
\advance\dimen@\minalignvsep
\ht\strutbox@\dimen@
\fi\fi
\strut@
\ifmeasuring@\savefieldlength@\fi
\set@field
\hfil
\tabskip\alignsep@
}
\makeatother
\minalignvsep.15em
\begin{document}
\begin{minipage}[t]{0.20\linewidth}
\textbf{Nice}
\begin{align*}
x &= 73 \times 2\\
&= 146
\end{align*}
\end{minipage}%
%
\begin{minipage}[t]{0.25\linewidth}
\textbf{Not so nice}
\begin{align*}
x &= \frac{146}{10}\\
&= \frac{73}{5}
\end{align*}
\end{minipage}%
\bigskip\par\noindent
\textbf{Manual Tweak Options:}
\medskip\par\noindent
\begin{minipage}[t]{0.25\linewidth}
\textbf{Tweak jot}
\setlength{\jot}{8pt}% tweak
\begin{align*}
x &= \frac{146}{10}\\
&= \frac{73}{5}
\end{align*}
\end{minipage}%
%
\begin{minipage}[t]{0.30\linewidth}
\textbf{Add vertical space}
\begin{align*}
x &= \frac{146}{10}\\[5pt]% tweak
&= \frac{73}{5}
\end{align*}
\end{minipage}%
%
\begin{minipage}[t]{0.30\linewidth}
\textbf{spreadlines}
\begin{spreadlines}{0.8em}% tweak
\begin{align*}
x &= \frac{146}{10}\\
&= \frac{73}{5}
\end{align*}
\end{spreadlines}
\end{minipage}%
\end{document}