如何使公式在对齐环境中占据相等的垂直空间?

如何使公式在对齐环境中占据相等的垂直空间?

考虑以下代码:

\begin{align}
f_1(x) &= \frac{15x}{3} \\
f_2(x) &= 3x + 5 \\
f_3(x) &= 4x + 13
\end{align}

这样就产生了三条线,其中第一条线比其他线占用更多的垂直空间。有没有办法让所有线占用相同的垂直空间(实际上意味着所有线都占用与最大线一样多的垂直空间)?

答案1

我不知道有没有自动的方法可以做到这一点,但在特殊情况下,您可以使用\vphantom它来实现这一点。

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
f_1(x) &= \frac{15x}{3} \\
f_2(x) &= \vphantom{\frac11}3x + 5 \\
f_3(x) &= \vphantom{\frac11}4x + 13
\end{align}
\end{document}

替代文本

答案2

如果你不想全局改变它,请将完整的公式放入{...}

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\savebox\strutbox{$\vphantom{\dfrac11}$}
\begin{align}
  f_1(x) &= \frac{15x}{3} \\
  f_2(x) &= 3x + 5 \\
  f_3(x) &= 4x + 13
\end{align}

\end{document}

答案3

我可以提供 TH 答案的变体,它会产生较少的垂直空间,但它会根据您的具体情况进行调整:只有第二线路需要一些额外的深度。这种比较特殊的调整的好处是,它不会产生额外的空白以下显示器。

\documentclass{article}
\usepackage{amsmath}
\begin{document}
Here's some text just to fill the line sufficiently
\begin{align}
f_1(x) &= \frac{15x}{3} \\
f_2(x) &= 3x + 5 \vphantom{\smash[t]{\frac11}} \\
f_3(x) &= 4x + 13
\end{align}
Here's some text just to fill the line sufficiently
\end{document}

相关内容