%&pdflatex
% Modyf. 11.9.09
\documentclass[leqno,twoside]{article}
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\textwidth=13.5cm
\textheight=23cm
\parindent=0pt
\parskip=6pt
\voffset=-1cm
\oddsidemargin=0cm
\evensidemargin=0cm
\pagestyle{myheadings}
\markboth{Multiline formulas}{Multiline formulas}
\newcommand{\bul}{$\bullet$~}
\newcommand{\bsl}{\textbackslash}
\newcommand{\spa}{\textvisiblespace}
\frenchspacing
\numberwithin{equation}{section}
\begin{document}
\title{\textbf{Multiline formulas}}
\author{Publications Department of IMPAN\\\texttt{publ@impan.pl}}
\date{}
\maketitle
\bul \emph{A general remark}: the constructs (``environments'') discussed below require the use of the \texttt{amsart} style or \texttt{\bsl usepackage\{amsmath\}} and are of two types:
\begin{itemize}
\item[(1)] the \texttt{align}, \texttt{gather}, \texttt{multline} and \texttt{alignat} environments concern the whole equations, i.e. they replace \texttt{equation} (an exception: \texttt{align} can be used inside \texttt{gather});
\item[(2)] \texttt{split}, \texttt{aligned}, \texttt{gathered} and \texttt{alignedat} are ``subsidiary environments'': they can only appear inside others, like \texttt{equation}, \texttt{align} or \texttt{gather}, and may embrace only some part of a displayed line.
\end{itemize}
\bul \emph{A piece of advice}: forget \texttt{eqnarray}!
\section{Several formulas or sets of displayed conditions}
\bul Separate formulas should end with a comma or semicolon---to make it clear that the next line is not a continuation of the preceding one.
\bul If there are no natural places for vertical alignment, use \texttt{gather}:
\begin{gather}
aaaaaaaaaa=b, \quad\ cc = xxx, \quad\ dd = yyy, \label{E:g1}\\
mmmmmmmmmmmmm=0 \quad\ \text{for all }i=1,\ldots,n. \label{E:g2}
\end{gather}
Note the spacing between parts of a formula on the same line; you can use
\texttt{\bsl quad} (small space), \texttt{\bsl quad\bsl\spa} (medium space)
or \texttt{\bsl qquad} (large space).
\bul If a formula number is unnecessary, you can ``switch it off'', using \texttt{\bsl notag}:
\begin{gather}
aaaaaaaaaa=b, \quad\ cc = xxx, \quad\ dd = yyy, \notag\\
mmmmmmmmmmmmm=0 \quad\ \text{for all }i=1,\ldots,n. \label{E:g3}
\end{gather}
(A formula number not cited in text is ``information noise''; also, the number takes some space and often causes the formula to occupy one line more. As a rule, number only those formulas that are referred to later.)
\bul If no number is necessary, use \texttt{gather*}:
%%
\begin{gather*}
aaaaaaaaaa=b, \quad\ cc = xxx, \quad\ dd = yyy,\\
mmmmmmmmmmmmm=0 \quad\ \text{for all }i=1,\ldots,n.
\end{gather*}
%%
\bul If you need one centred number (for a~group of equations),
instead of \texttt{gather} use \texttt{gathered} inside \texttt{equation}:
%%
\begin{equation} \label{E:g4}
\begin{gathered}
aaaaaaaaaa=b, \quad\ cc = xxx, \quad\ dd = yyy,\\
mmmmmmmmmmmmm=0 \quad\ \text{for all }i=1,\ldots,n.
\end{gathered}
\end{equation}
%%
\bul In most cases, however, we want to align something, and then we use \texttt{align}:
%%
\begin{align}
xxxxx &= yyyyyyyyyyyyyy \label{E:a1}\\
&\quad + zzzzzzzzzzzzzzzzzz, \notag\\
bbb &= tttttttttttttttttt, \label{E:a2}\\
hh &= vvvvvvvvvvv. \label{E:a3}
\end{align}
%%
Note that the alignment symbols, called ampersands (\texttt{\&}), should be placed
\textbf{to the left} of binary relation signs; if, as above, part of an expression is continued on the next line, put \texttt{\&\bsl quad} before the binary operation sign.
Remember that you cannot place \texttt{\&} signs anywhere:
the parts between two \texttt{\&} signs and between \texttt{\&} and \texttt{\bsl\bsl} should be ``separate formulas'' (in the \TeX~sense), so you cannot e.g. put a \texttt{\&} inside \texttt{\{}~\texttt{\}} or inside \texttt{\bsl left}-\texttt{\bsl right}.
\bul If you need one centred number for a group of aligned equations, use \texttt{split} or \texttt{aligned} inside \texttt{equation}:
%%
\begin{equation}\label{E:a4}
\begin{split}
xxxxx &= yyyyyyyyyyyyyy\\
&\quad + zzzzzzzzzzzzzzzzzz,\\
bbb &= tttttttttttttttttt,\\
hh &= vvvvvvvvvvv.
\end{split}
\end{equation}
%%
\bul If you have two ``split'' sets of equations and you want them to have a common alignment, you have to use two \texttt{split}'s inside \texttt{align} (this is the advantage of \texttt{split} over \texttt{aligned}):
%%
\begin{align}
\begin{split}
aaaaaaaaaaaaaaaaaaaaaaa &= bbbbbbbbbbbbb,\\
bbbb &= xxxxxx,
\end{split}\label{Ea5}\\
\begin{split}
ccccc &= yyyyyyy,\\
dddddddd &= zzzzz.\label{E:a6}
\end{split}
\end{align}
%%
If you do not want ``aligned alignments'', use \texttt{split} or \texttt{aligned} inside \texttt{gather}:
%%
\begin{gather}
\begin{split}
& aaaaaaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbb,\\
& bbbbbbbbbbbbbbbbbbbbbbbb = xxxxxx,
\end{split} \label{E:a7}\\
\begin{split}
& ccccc = yyyyyyy,\\
& dddddddd = zzzzz.
\end{split}\label{E:a8}
\end{gather}
%%
\bul If you need several aligned ``columns'', you can still use \texttt{align} or \texttt{align*}, but you have to add additional ampersands separating the columns:
%%
\begin{align*}
aa &= bbbbb, & dd &= ee & &\text{(by Lemma 2),}\\
hh &= ii, & ll &= kkkkkk & &\text{(by \eqref{E:a8}).}
\end{align*}
%%
However, here you do not control the spacing between the columns. If you want to prescribe it,
use \texttt{alignat} (or \texttt{alignat*}), which has a parameter (the number of columns) and requires specifying the intercolumn spaces:
%%
\begin{alignat}{3}
aa &= bbbbb,\quad\ & dd &= ee & &\text{(by Lemma 2),} \label{E:a9}\\
hh &= ii, & ll &= kkkkkk\quad\ & &\text{(by \eqref{E:a8}). \label{E:a10}}
\end{alignat}
%%
\bul \texttt{alignat} also has a subsidiary version, \texttt{alignedat}, which you can put inside \texttt{equation} if you need one centred number:
%%
\begin{equation}\label{E:a11}
\begin{alignedat}{3}
aa &= bbbbb,\quad\ & dd &= ee & &\text{(by Lemma 2),}\\
hh &= ii, & ll &= kkkkkk\quad\ & &\text{(by \eqref{E:a8}).}
\end{alignedat}
\end{equation}
%%
\bul If you want the consecutive equations of a group of equations to be numbered (2a), (2b) etc., use \texttt{subequations}, inside which you can place the previous constructs, e.g., \texttt{alignat} inside \texttt{subequations}:
%%
\begin{subequations}\label{E:suba}
\begin{alignat}{3}
aa &= bbbbb,\quad\ & dd &= ee & &\text{(by Lemma 2),} \label{E:suba1}\\
hh &= ii, & ll &= kkkkkk\quad\ & &\text{(by \eqref{E:a8}).} \label{E:suba2}
\end{alignat}
\end{subequations}
%%
or \texttt{gather} inside \texttt{subequations}:
%%
\begin{subequations}\label{E:subg}
\begin{gather}
\begin{split}
& aaaaaaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbb, \\
& bbbbbbbbbbbbbbbbbbbbbbbb = xxxxxx,
\end{split}\label{E:subg1}\\
\begin{split}
& ccccc = yyyyyyy,\\
& dddddddd = zzzzz.
\end{split}\label{E:subg2}
\end{gather}
\end{subequations}
%%
Note the independent labels of the whole group and its parts;
writing \texttt{\bsl eqref\{E:suba\}}, we invoke the whole system
\eqref{E:suba}, while writing \texttt{\bsl eqref\{E:suba1\}} we refer to \eqref{E:suba1}.
\section{One multiline formula}
\bul Quite often one formula (i.e. a sequence of expressions connected by binary operations and relations) takes more than one line.
As a rule, one formula (in this sense) should have one number; numbering parts of it separately is seldom necessary. In case of need, you can refer to a specific line of a formula by writing e.g.
\eqref{E:m1}$_2$.
If equation numbers are placed on the left (as in the \texttt{amsart} style, and also in IMPAN journals), the number is normally on the first line of a multiline formula;
if the numbers are on the right, it is on the last line.
(Warning: this convention is followed by many publishers, but not all: sometimes the number is centred.)
\bul If there are no natural places for alignment, use
\texttt{multline}:
%%
\begin{multline}\label{E:m1}
aaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\\\le dddddddddddddddddddddddddd.
\end{multline}
%%
The first line is set (almost) flush left, the last line is (almost) flush right, and the middle lines (if any) are centred.
\bul You can shove any middle line within \texttt{multline} to the right or to the left by making it the argument of \texttt{\bsl shoveright} or \texttt{\bsl shoveleft}:
%%
\begin{multline}\label{E:m2}
aaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
\shoveleft{+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb+dddddddddd}\\
\shoveright{\times eeeeeeeeeeeeeeeeeeeeeeee}\\
\le dddddddddddddddddddddddddd.
\end{multline}
%%
\bul You can align a group of lines within \texttt{multline}, using \texttt{aligned} (or \texttt{split}, but then you get a warning that \texttt{split} will be replaced by \texttt{aligned}):
%%
\begin{multline}\label{E:m3}
aaaaaaaaaaaaaaaaa + xxxxxxxxxxxx\\
\begin{aligned}
&< bbbbbbbbbbbbbbbbbbbbbbb\\
&\quad + ddddddddddddddddddddddddddddddddddddd\\
&< ccccccccccccccccccc.
\end{aligned}
\end{multline}
%%
\bul To code an ``object'' consisting of centred lines within a formula, use \texttt{gathered}:
%%
\begin{equation}\label{E:pasc}
\mathrm{Pascal}_{4} =
\begin{gathered}
1\\
1\ 2\ 1\\
1\ 3\ 3\ 1\\
1\ 4\ 6\ 4\ 1
\end{gathered}
\end{equation}
%%
If you want to bottom-align two such objects, apply
\texttt{gathered[b]}:
%%
\begin{equation*}
\begin{gathered}[b]
1\\
1\ 2\ 1\\
1\ 3\ 3\ 1
\end{gathered}
\qquad
\begin{gathered}[b]
1\\
1\ 2\ 1\\
1\ 3\ 3\ 1\\
1\ 4\ 6\ 4\ 1
\end{gathered}
\end{equation*}
%%
With \texttt{gathered[t]}, you get top alignment:
%%
\begin{equation*}
\begin{gathered}[t]
1\\
1\ 2\ 1\\
1\ 3\ 3\ 1
\end{gathered}
\qquad
\begin{gathered}[t]
1\\
1\ 2\ 1\\
1\ 3\ 3\ 1\\
1\ 4\ 6\ 4\ 1
\end{gathered}
\end{equation*}
%%
\bul The \texttt{aligned[t]} and \texttt{aligned[b]} constructions enable independent and/or nested alignments, e.g.,
\texttt{aligned[t]} inside \texttt{align}:
%%
\begin{align}\label{E:top}
A &= xyzt = ztuv + \begin{aligned}[t]
[&f_1(a,b,c,d,e,f,g,h),\\
&f_2(a,b,c,d,e,f,g,h),\\
&f_3(a,b,c,d,e,f,g,h)]
\end{aligned}\\
&= cccccccccccccc\notag
\end{align}
%%
or \texttt{aligned[b]} inside \texttt{align*}:
%%
\begin{align*}
\begin{aligned}[b]
xxxxxxx + [&f_1(a,b,c,d,e,f,g,h),\\
&f_2(a,b,c,d,e,f,g,h),\\
&f_3(a,b,c,d,e,f,g,h)]
\end{aligned}
&= tttttttttttttttttttttttttt\\
&= bbbbbbbbbbbbbb.
\end{align*}
\bul \texttt{aligned[t]} can also be used, somewhat artificially, when there are no natural places for alignment, but we want to shove a line of \texttt{align} to the right:
%%
\begin{align}\label{E:shove}
xxxxx &= \begin{aligned}[t] yyyyyyyyyyyyyy +
[&eeee \\
&\times zzzzzzzzzzzzzzzzzz]
\end{aligned} \\
&= tttttttttttttttttt \notag\\
&= vvvvvvvvvvv.\notag
\end{align}
%%
\bul If you want to place a longer comment in the middle of an aligned construction, you can use \texttt{\bsl intertext}:
%%
\begin{align}
xxxxx &= \begin{aligned}[t] yyyyyyyyyyyyyy +
[&eeee \\
&\times zzzzzzzzzzzzzzzzzz]
\end{aligned}\label{E:inter} \\
\intertext{(\emph{note that we have not used the full strength of $(H)$ here, but only the concavity of $f$})}
&= tttttttttttttttttt \notag\\
&= vvvvvvvvvvv.\notag
\end{align}
%%
\begin{thebibliography}{1}
\bibitem{Gratzer} G. Gr\"atzer,
\emph{More Math into \LaTeX},
4th ed., Springer, Berlin, 2007.
\end{thebibliography}
\end{document}