%&pdflatex

% Modif. 30.3.18
\documentclass[leqno,twoside]{article}
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage{enumitem}

\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}

\newcommand{\Item}{\refstepcounter{equation}\item}

\frenchspacing

\numberwithin{equation}{section}

\begin{document}


\title{\textbf{Multiline formulas}}
\author{Publications Department of IMPAN\\\texttt{publ@impan.pl}\\
\texttt{https://www.impan.pl/en/publishing-house/for-authors}}

\date{\today}

\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{enumerate}[label=(\arabic*), leftmargin=*]
\item 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 \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{enumerate}

Some constructs below require \texttt{\bsl usepackage\{mathtools\}} or \texttt{\bsl usepackage\{enumitem\}}. 

\bul \emph{A piece of advice}: forget \texttt{eqnarray}!

\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.\vadjust{\eject}

\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}:
%%
\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]} (then you have to add \texttt{split} to centre the equation number):
%%
\begin{equation}
\begin{split}
\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{split}
\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{aligned}: 
%%
\begin{equation}\label{E:top}
\begin{aligned}[t]
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
\end{aligned}
\end{equation}
%%
or \texttt{aligned[b]} inside \texttt{aligned}:
%%
\begin{equation*}      
\begin{aligned}
  \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{aligned}
\end{equation*}



\bul To move a line within an aligned structure to the left or to the right, use \texttt{MoveEqLeft} with a positive or negative parameter (this requires \texttt{\bsl usepackage\{mathtools\}}):
%
\begin{equation}\label{E:shove1}
\begin{aligned}[t]
xxxxx &=  yyyyyyyyyyyyyy + [eeee    \\
 \MoveEqLeft[-10] \times zzzzzzzzzzzzzzzzzz] \\          
   &= tttttttttttttttttt  \\
   &= vvvvvvvvvvv.         
\end{aligned}
\end{equation}
%%

\bul If the formulas are left-numbered, you can also label a longer statement as a ``formula'', by treating it as an item of an itemized list (this requires \texttt{\bsl usepackage\{enumitem\}}; the ``leftmargin'' parameter has to be adjusted according to the width of the formula number):
%
\begin{enumerate}[label=(\theequation), ref=\theequation, leftmargin=2.5em]
\Item\label{E:text4} Here you can place any statement, even taking several lines of text and including displayed formulas, like
\[
aaaa=bbb.
\]
\Item\label{E:text5}  Next item.
\end{enumerate}



\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}
\vadjust{\eject}

\bul You can also ``gather'' several ``multlines'', using the subsidiary construct \texttt{multlined}, available in \texttt{mathtools}, with optional parameters indicating the placement of formula numbers and the width of the formulas:
%
\begin{gather}
\begin{multlined}[t][10cm] \label{E:m4}
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\\
\shoveright{\times yyyyyyyyyyy}\\
=xxxxxxxxxxxxxxxxxxxxxxxxxxxx,
\end{multlined}\\
\begin{multlined}[t][10cm] \label{E:m5}
cccccccccccccccccccccccccccccccccccccccc\\
=ddddddddddddddddddddddddddddddddddddddddd.
\end{multlined}
\end{gather}


\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 e.g. (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}.

\bul If you want to place a longer comment in the middle of an aligned construction, you can use \texttt{\bsl intertext} (this only works within \texttt{align} or \texttt{align*}, but not with \texttt{aligned}):
%%
\begin{align} \label{E:inter}
xxxxx &=  yyyyyyyyyyyyyy + [eeee \\
         \MoveEqLeft[-10] \times zzzzzzzzzzzzzzzzzz]  \notag\\         
\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}