## 2011年9月20日星期二

### LaTeX Align (environment)

The align environment is used for two or more equations when vertical alignment is desired; usually binary relations such as equal signs are aligned.

For all intents and purposes, it's a replacement for the eqnarray environment and all its warts. Rather than

\begin{eqnarray*}
x^2 + y^2 &=& 1
\\ y &=& \sqrt{1 - x^2},
\end{eqnarray*}

one can type
\begin{align*}
x^2 + y^2 &= 1
\\ y &= \sqrt{1 - x^2}.
\end{align*}

Benefits over eqnarray

Besides the slightly simpler syntax, you can
Inconsistent spacing around binary symbols like = and +;
Overwriting equation numbers; and
Silent label mismatch.

Multiple equations on one line

Besides being used for aligning binary symbols, the ampersand can also mark an invisible alignment for separating columns of equations. For example,

\begin{align*}
u &= \arctan x & dv &= 1 \, dx
\\ du &= \frac{1}{1 + x^2} dx & v &= x.

Preamble

To use align, import the amsmath package in your preamble.

\usepackage{amsmath}
\begin{align*}
u &= \arctan x & dv &= 1 \, dx
\\ du &= \frac{1}{1 + x^2} dx & v &= x.
\end{align*}
\end{align*}