align 和它的不带标号的版本 align* 可以排列多列对齐的公式,列与列之间用 & 分隔,而且在 & 左右的公式分别按照右对齐、左对齐的方式排列,所以很多人在用多个 & 时就从观感上容易产生很大的间距,相信这点你已经知道。在使用时,& 一般会放 = 的前面:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x &= t & x &= \cos t & x &= t^2 \\
y &= 2t & y &= \sin(t+1) & y &= e^t
\end{align*}
\end{document}
当然有时也可以放在二元运算符前面,只不过这时我通常会这么用(lshort-zh-cn 中也有类似的用法)
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
(a+b)^2 ={}& a^2 + b^2\\
& + 2ab
\end{align*}
\end{document}
alignat 及不带标号的 alignat* 则不在列与列之间产生间距,但可以手工增加间距。alignat 环境有一个参数,表示每行要对齐的公式个数,每两列一组,如下面把列间距设定为一个 \quad 的距离
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{2}
x &= \sin t & \quad & t \ge 0 \\
y &= \cos t & & t < 0
\end{alignat*}
\end{document}
看第2行第3列我没用 \quad,但是间距依然保留下来,这是因为上一行的 \quad 位置必须在每一行都有所体现。它的这种特性就非常适合排版线性方程组
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{6}
& x_1 & & + x_2 & & +x_3 & &+ x_4 & &+ x_5 & &=1 \\
& x_1 & & & & +x_3 & & & & + x_5 & &=2 \\
& & & \mathbin{\phantom{+}}x_2 & & & & +x_4 & & & &=3
\end{alignat*}
\end{document}
关于 \mathbin,可以参考 tex.stackexchange.com 的解释。\phantom 则是产生一个幻影。







问 align和alignat环境的区别以及适用范围?