# Alignment of formulas

Richard Kaye
School of Mathematics and Statistics
The University of Birmingham
Birmingham B15 2TT
U.K.
12th August 1998
1 Introduction
One of the most diﬃcult aspects of typesetting mathematics is splitting long
formulas across several lines and aligning a group of formulas. Many of these
aspects cannot be done automatically, and it is up to you to control how this is
to done. In all cases, your judgement should be based on making the formula
Some control is available using L
A
T
E
X’s eqnarray and eqnarray* environ-
ments. However, this command is rather limited for many applications and if
you are creating a new document in which you envisage a large number of long
formulas or equations I strongly recommend you use the AMS packages that are
available.
2 Using the package
Unless you are using one of the AMS’s own class ﬁles, you load the package by
the command \usepackage{amsmath}. This loads lots of useful new commands,
including the alignment environments referred to earlier. These are:
1. equation essentially as usual
2. multline for single equations or formulas going over two or more lines
3. split as for multline, but with extra control over alignment
4. gather for several equations grouped together
5. align for several equations grouped together, with alignment
6. alignat similar to align but with some extra alignment features
In most cases, there are starred and unstarred versions of these—the starred
versions do not produce any numbering automatically. There are a few other
related commands, such as: the \intertext command which interpolates text
1
without messing up the alignment; the subequations environment which num-
bers a groups of equations as 5a, 5b, 5c, etc.; the cases environment for deﬁni-
tions by cases, and a few other useful things. I’m not going to describe in detail
how these commands ae used—you can get that from the documentation. In-
stead, the next section contains some examples and you can quickly get started
by comparing the output with the L
A
T
E
X source, which is called align.tex and
can be obtained from the usual directory.
3 Examples
Many of these examples are directly taken from the documentation of AMSL
A
T
E
X,
which is recommended reading if further details are required.
Use of equation*:
a = b
Use of equation:
a = b (1)
Use of split and equation:
a = b + c − d
+ e − f
= g + h
= i
(2)
Use of multline:
a + b + c + d + e + f + b + c + d + e + f + b + c + d + e + f
+ b + c + d + e + f + b + c + d + e + f + i + j + k + l + m + n (3)
Use of gather:
a
1
= b
1
+ c
1
(4)
a
2
= b
2
+ c
2
− d
2
+ e
2
(5)
Use of align:
a
1
= b
1
+ c
1
(6)
a
2
= b
2
+ c
2
− d
2
+ e
2
(7)
Other uses for align:
a
11
= b
11
a
12
= b
12
(8)
a
21
= b
21
a
22
= b
22
+ c
22
(9)
Use of flalign*:
a
11
= b
11
a
12
= b
12
a
21
= b
21
a
22
= b
22
+ c
22
2
Use of \equation and \split:
H
c
=
1
2n
n
¸
l=0
(−1)
l
(n − l)
p−2
¸
l
1
+···+l
p
=l
p
¸
i=1

n
i
l
i

· [(n − l) − (n
i
− l
i
)]
n
i
−l
i
·

(n − l)
2

p
¸
j=1
(n
i
− l
i
)
2

.
(10)
Use of \align to align textual annotations:
x = y
1
− y
2
+ y
3
− y
5
+ y
8
− . . . by (14) (11)
= y

◦ y

by (5) (12)
= y(0)y

by Axiom 1. (13)
Use of \aligned to control placement of inner alignments:
α = αα
β = βββββ
γ = γ
versus δ = δδ
η = ηηηηηη
ϕ = ϕ
“Cases” constructions:
P
r−j
=

0 if r − j is odd,
r! (−1)
(r−j)/2
if r − j is even.
(14)
Use of \smash and \vphantom to control vertical size:

u
n
¸
i=1
F(e
i
, v)e
i

=
n
¸
i=1
F(e
i
, v)u|e
i

=
n
¸
i=1
u|e
i
F(e
i
, v)
=
n
¸
i=1
e
i
|uF(e
i
, v)
= F

n
¸
i=1
e
i
|ue
i
, v

= F(u, v),
(Note that without \phantom and \smash the brackets would be too big because
of the limits on the summations.) \phantom is also useful if you are splitting
a long equation over two lines and you want a large left bracket on one line to
match a large right bracket on the next:
x =
1
2

n
¸
i=1
F(e
i
, v)e
i
+
n
¸
i=1
G(e
i
, v)e
i
+
n
¸
i=1
H(e
i
, v)e
i
+
n
¸
i=1
I(e
i
, v)e
i
+
n
¸
i=1
K(e
i
, v)e
i
+
n
¸
i=1
J(e
i
, v)e
i

(Note also the adjustment to the vertical spacing in this example.)
Use of \intertext:
3
Proof. (a) Given v, we have
1 v = (−1)(−1)v
= (−1)(−1)v +0
= (−1)(−1)v + (v + (−1)v)
= (−1)(−1)v + ((−1)v +v)
= ((−1)(−1)v + (−1)v) +v
= 0 +v
= v.
(b) Again,
0 v = (1 + (−1))v
= 1v + (−1)v
= v + (−1)v
= 0.
For (c),
λ0 = λ(0 + (−1)0)
= λ0 + λ((−1)0)
= λ0 + (−1)(λ0)
= 0
as required
4 ACA ESTA EL LISTADO QUE GENERO
EL ANTERIOR DOCUMENTO
\documentclass[a4paper]{article}
\usepackage{amsmath,amsthm}
\newcommand{\fn}[1]{\texttt{#1}}
\newcommand{\cn}[1]{\texttt{\char92 #1}}
\title{Alignment of formulas}
\author{Richard Kaye\School of Mathematics and Statistics\
The University of Birmingham\Birmingham B15 2TT\U.K.}% If you
% change the document in any way, put your own name here instead of mine
\date{12th August 1998}
\begin{document}
\maketitle
4
\section{Introduction}
One of the most difficult aspects of typesetting mathematics is
splitting long formulas across several lines and aligning a group
of formulas. Many of these aspects cannot be done automatically,
and it is up to you to control how this is to done. In all cases,
as possible.
Some control is available using \LaTeX’s \fn{eqnarray} and
\fn{eqnarray*} environments. However, this command is rather
limited for many applications and if you are creating a new
document in which you envisage a large number of long formulas or
equations I strongly recommend you use the AMS packages that are
available.
\section{Using the package}
Unless you are using one of the AMS’s own class files, you load
the package by the command \cn{usepackage}\verb|{amsmath}|. This
loads lots of useful new commands, including the alignment
environments referred to earlier. These are:
\begin{enumerate}
\item \fn{equation} essentially as usual \item \fn{multline} for
single equations or formulas going over two or more lines \item
\fn{split} as for multline, but with extra control over alignment
\item \fn{gather} for several equations grouped together \item
\fn{align} for several equations grouped together, with alignment
\item \fn{alignat} similar to align but with some extra alignment
features
\end{enumerate}
In most cases, there are starred and unstarred versions of
these---the starred versions do not produce any numbering
automatically. There are a few other related commands, such as:
the \cn{intertext} command which interpolates text without messing
up the alignment; the \fn{subequations} environment which numbers
a groups of equations as \textit{5a}, \textit{5b}, \textit{5c},
etc.; the \fn{cases} environment for definitions by cases, and a
few other useful things. I’m not going to describe in detail how
these commands ae used---you can get that from the documentation.
Instead, the next section contains some examples and you can
quickly get started by comparing the output with the \LaTeX\
source, which is called \fn{align.tex} and can be obtained from
the usual directory.
\section{Examples}
Many of these examples are directly taken from the documentation
of AMS\LaTeX, which is recommended reading if further details are
5
required.
Use of \fn{equation*}:
\begin{equation*}
a=b
\end{equation*}
Use of \fn{equation}:

a=b

Use of \fn{split} and \fn{equation}:
\label{xx}
\begin{split}
a& =b+c-d\
& =g+h\
& =i
\end{split}

Use of \fn{multline}:
\begin{multline}
a+b+c+d+e+f+b+c+d+e+f+b+c+d+e+f\
+b+c+d+e+f+b+c+d+e+f+i+j+k+l+m+n
\end{multline}
Use of \fn{gather}:
\begin{gather}
a_1=b_1+c_1\
a_2=b_2+c_2-d_2+e_2 \label{eq:D}
\end{gather}
Use of \fn{align}:
\begin{align}
a_1& =b_1+c_1\
a_2& =b_2+c_2-d_2+e_2
\end{align}
Other uses for \fn{align}:
\begin{align}
a_{11}& =b_{11}&
a_{12}& =b_{12}\
a_{21}& =b_{21}&
a_{22}& =b_{22}+c_{22}
\end{align}
Use of \fn{flalign*}:
\begin{flalign*}
a_{11}& =b_{11}&
a_{12}& =b_{12}\
a_{21}& =b_{21}&
a_{22}& =b_{22}+c_{22}
\end{flalign*}
Use of \cn{equation} and \cn{split}:
\label{e:barwq}\begin{split}
6
H_c&=\frac{1}{2n} \sum^n_{l=0}(-1)^{l}(n-{l})^{p-2}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\
)^2-\sum^p_{j=1}(n_i-l _i)^2\Bigr].
\end{split}
Use of \cn{align} to align textual annotations:
\begin{align}
x& = y_1-y_2+y_3-y_5+y_8-\dots
&& \text{by \eqref{eq:C}}\
& = y’\circ y^* && \text{by \eqref{eq:D}}\
& = y(0) y’ && \text {by Axiom 1.}
\end{align}
Use of \cn{aligned} to control placement of inner alignments:
\begin{equation*}
\begin{aligned}
\alpha&=\alpha\alpha\
\beta&=\beta\beta\beta\beta\beta\
\gamma&=\gamma
\end{aligned}
\begin{aligned}[t]
\delta&=\delta\delta\
\eta&=\eta\eta\eta\eta\eta\eta\
\varphi&=\varphi
\end{aligned}
\end{equation*}
‘‘Cases’’ constructions:
\label{eq:C}
P_{r-j}=
\begin{cases}
0& \text{if $r-j$ is odd},\
r!\,(-1)^{(r-j)/2}& \text{if $r-j$ is even}.
\end{cases}

Use of \cn{smash} and \cn{vphantom} to control vertical size:
\newcommand\ip[2]{\langle #1 \/ | #2 \/\rangle}
\newcommand\Ip[2]{\left\langle{\arraycolsep=0pt %
\begin{array}{c|c}#1\/\,&\,#2\/\end{array}}%
\right\rangle}
\newcommand\Ipd[2]{\left\langle{\arraycolsep=0pt %
\begin{array}{c|c}\displaystyle#1\/\,&\,\displaystyle#2\/\end{array}}%
\right\rangle}
\newcommand\conj[1]{\overline{#1}}
\begin{align*}
\Ipd{ u\: }{\: \smash{\sum_{i=1}^n F(e_i,v) e_i }\vphantom{\sum}}
&= \sum_{i=1}^n F(e_i,v) \ip{ u }{ e_i } \
&= \sum_{i=1}^n \ip{ u }{ e_i } F(e_i,v) \
&= \sum_{i=1}^n \conj{\ip{ e_i }{ u }} F(e_i,v) \
&= F \biggl( \sum_{i=1}^n \ip{ e_i }{ u } e_i,v\biggr) = F( u, v
),
7
\end{align*}
(Note that without \cn{phantom} and \cn{smash} the brackets would
be too big because of the limits on the summations.) \cn{phantom}
is also useful if you are splitting a long equation over two lines
and you want a large left bracket on one line to match a large
right bracket on the next:
\begin{align*}
x&= \frac{1}{2} \left(\smash{\sum_{i=1}^n F(e_i,v) e_i
}\vphantom{\sum}+
\smash{\sum_{i=1}^n G(e_i,v) e_i} +\smash{\sum_{i=1}^n H(e_i,v) e_i }\vphantom{\sum}+\right.\[8pt]
}\vphantom{\sum}+ \smash{\sum_{i=1}^n K(e_i,v) e_i} +
\smash{\sum_{i=1}^n J(e_i,v) e_i}\vphantom{\sum}\right)
\end{align*}
(Note also the adjustment to the vertical spacing in this
example.)
Use of \cn{intertext}:
\begin{proof} (a) Given $\mathbf v$, we have
\begin{align*}
1\,\mathbf v &= (-1)(-1)\mathbf v \
&=(-1)(-1)\mathbf v +\mathbf 0 \
&=(-1)(-1)\mathbf v + (\mathbf v + (-1)\mathbf v) \
&=(-1)(-1)\mathbf v + ((-1)\mathbf v + \mathbf v) \
&=((-1)(-1)\mathbf v + (-1)\mathbf v) + \mathbf v \
&= \mathbf 0+\mathbf v \
&= \mathbf v. \
\intertext{(b) Again,}
0\,\mathbf v &= (1+(-1))\mathbf v \
&= 1\mathbf v+(-1)\mathbf v\
&= \mathbf v+(-1)\mathbf v \
&= \mathbf 0.\
\intertext{For (c),}
\lambda \mathbf 0 &= \lambda(\mathbf 0 + (-1)\mathbf 0) \
&= \lambda \mathbf 0 + \lambda((-1)\mathbf 0) \
&= \lambda \mathbf 0 + (-1)(\lambda \mathbf 0) \
&=\mathbf 0
\end{align*}
as required.
\end{proof}
\end{document}
8