How to align equations in LaTeX?

Aligning equations is a very useful ability in mathematical writing since it greatly improves the readability of long equations and sequences of implications that otherwise would be unreadable.

There are several methods to align a set of equations inside LaTeX. Here we are going to discuss some of these techniques, their similarities, and also their differences. Most of the features will be provided by the amsmath package. This package, written by the American Mathematical Society and part of the AMS-LATEX distribution, provides a lot of tools that are indispensable to a professional mathematical writing in LaTeX.

Here we will only explore a very tiny portion of all amsmath package capabilities.

1. Left alignment of multiline equations in LaTeX

The first environment from the amsmath package that we are going to explain is the flalign environment. This environment is characterized by the fact that multiline equations are left-aligned.

The following example shows how one can use this environment:

% Left alignment of multiline equations

\begin{flalign}
f(u) & =\sum_{j=1}^{n} x_jf(u_j)&\\
& =\sum_{j=1}^{n} x_j \sum_{i=1}^{m} a_{ij}v_i&\\
& =\sum_{j=1}^{n} \sum_{i=1}^{m} a_{ij}x_jv_i
\end{flalign}

It should be noted that the amsmath package is required to be able to use this environment. Hence, do not forget to add \usepackage{amsmath} to the document preamble. The above code produces the following:

Observe how the symbols used to separate different columns and lines are the same ones as for the tabular environment.

To produce left-aligned formulas, a column separator & must be put before the line break \\; in other cases, the formulas will be aligned in the center as in the rest of the environments that we will show.

a. Remove multiline equations numbering

Note also that different lines are considered different formulas, and thus are numbered independently; in case you don’t want them to be numbered, you can use the starred version of the environment flalign*.

Consider the previous example:

% Remove numbering in multiline equations 1

\begin{flalign*}
f(u) & =\sum_{j=1}^{n} x_jf(u_j)&\\
& =\sum_{j=1}^{n} x_j \sum_{i=1}^{m} a_{ij}v_i&\\
& =\sum_{j=1}^{n} \sum_{i=1}^{m} a_{ij}x_jv_i
\end{flalign*}

which will produce the following output:

This will also be a recurring feature in the environments that will be explained: all the equation like environments will have their starred version, which will be unnumbered.

b. Remove numbering from specific lines of multline equations

But what if we want single equality to be numbered, because it will be used in the following, but the rest to be unnumbered because they are simple calculations?

Well, for this purpose we have the useful \nonumber command. This command eliminates the numbering from an equation, and since inside the flalign environment each line is treated as a single equation, we can eliminate the numbers independently, using \nonumber only in the lines we want to appear without any numbering.

For instance, if only the first equality will be reused in the following text, the code

% Remove numbering in multiline equations 2

\begin{flalign}
f(u) & =\sum_{j=1}^{n} x_jf(u_j)&\\ \nonumber
& =\sum_{j=1}^{n} x_j \sum_{i=1}^{m} a_{ij}v_i&\\ \nonumber
& =\sum_{j=1}^{n} \sum_{i=1}^{m} a_{ij}x_jv_i
\end{flalign}

produces the equations:

2. Multiline equations alignement: Method 2

A similar result is obtained when using the align environment. In this case, however, the contents will be centered on the page, and no & symbol should go before the line break. Check the following example:

% Align environment

\begin{align}
f(u) & =\sum_{j=1}^{n} x_jf(u_j)\\
& =\sum_{j=1}^{n} x_j \sum_{i=1}^{m} a_{ij}v_i\\
& =\sum_{j=1}^{n} \sum_{i=1}^{m} a_{ij}x_jv_i
\end{align}

which produces the following result:

As you can see, this environment also treats different lines as different equations, and thus we can make use of the \nonumber. There is also a starred version of the environment align*, that produces no numbers at all.

3. Aligned envirnoment to treat multiline equations as a one equation

Note that we have been cheating a bit, since the example we are always printing out consists in fact of a single equation with different equality signs. The previous environments were designed to separate clusters of different equations. The difference with the environments used to print one single equation is that the latter yield less space before and after the environment, and put a single number centered in the equation (in case we want it numbered)

The aligned environment can be used to display a single equation inside an array of multiple lines. This environment, in contrast with the previous ones, can only be used inside math mode. For example,

% Aligned environment

\begin{aligned} f(u) & =\sum_{j=1}^{n} x_jf(u_j)\\ & =\sum_{j=1}^{n} x_j \sum_{i=1}^{m} a_{ij}v_i\\ & = \sum_{j=1}^{n} \sum_{i=1}^{m} a_{ij}x_jv_i \end{aligned}

produces the output:

As you can see, we have used the equation environment to wrap aligned, instead of the usual display math environment \ [ … \ ] so that the whole equation is numbered.

Another option would be to use the split environment. This environment also has to go inside math mode. The output and usage is essentially the same as for the aligned environment, with the difference that it only supports one alignment column.

We reached the end of this tutorial, If you have any remarks or suggestions, please feel free to reach us via email at admin@latex-tutorial.com