Alignment

There are times when we want to show a sequence of equations, for example when showing work on an assignment.

If we enter all the equations on separate lines in inline math mode, they will be left-aligned. If we enter them in display mode, they will each be centered.

Multiple equations in inline math mode. The equations are all left-aligned.

Multiple equations in display mode. The equations are all centered.

However, there is another option, where we choose the points where the equations line up. For this, we will use an aligned environment.

Multiple equations in an aligned environment. The equations all line up at the equals signs.

Alignment can make groups of equations and expressions more readable. For example, the equations shown above are all aligned at the equals sign. This makes it easy for the reader to see the changes in each side of the equation.

Creating alignment

Copy the following set of equations into your project. At this point, they will all show up on the same line if you compile the preview.

\[

x^2 = 6 - x

x^2 + x - 6 = 0

(x - 2)(x + 3) = 0

x = 2, x = -3

\]

First, we place the equations inside of an aligned environment.

Recall that the document itself is an environment, defined by the commands \begin{document} and \end{document}. The aligned environment is similar.

An aligned environment in math mode is contained between the commands \begin{aligned} and \end{aligned}


Note that these commands can only be used in math mode.

Add the commands to place the equations inside of the environment:

\[

\begin{aligned}

x^2 = 6 - x

x^2 + x - 6 = 0

(x - 2)(x + 3) = 0

x = 2, x = -3

\end{aligned}

\]

Next, we want to put the equations on separate lines.

\\ (double backslash) adds a line break in an aligned environment.

Try adding a line break between each equation in the example:

\[

\begin{aligned}

x^2 = 6 - x \\

x^2 + x - 6 = 0 \\

(x - 2)(x + 3) = 0 \\

x = 2, x = -3 \\

\end{aligned}

\]

Finally, we set the point in each equation where we want them to align.

& (ampersand) sets the point of alignment.

Choose an alignment point in each equation.

For the first three lines, we can align at the equals sign. For the last, with the two solutions, we have two options. We could align at the first equals sign. The code shown below aligns instead at the comma, which makes the solutions centered.

\[

\begin{aligned}

x^2 &= 6 - x \\

x^2 + x - 6 &= 0 \\

(x - 2)(x + 3) &= 0 \\

x = 2 &, x = -3 \\

\end{aligned}

\]

On the next page, take a short quiz to review this last section of math typesetting.