Skip to main content

Easy elegance with {alignat}

·495 words·3 mins
MSP Staff
alignments fine points of typesetting math displays math environments
Table of Contents
Typesetting TeXniques - This article is part of a series.
Part 8: This Article

In the series Typesetting TeXniques, we share our expertise as professional copyeditors and typesetters of mathematics. We frequently hear from authors that our work makes their papers better. This is how we do it.

The amsmath package provides a number of environments for typesetting math displays containing multiple lines. They are designed to handle a variety of formatting needs. For example, the {alignat} and {alignat*} environments are used to typeset displays that call for alignment points. The most common use of {alignat} and {alignat*} is displaying multiple columns of equations:

Three columns of equations, aligned at equals signs.

Why {alignat} rather than {align}
#

You could typeset the math in the previous display using {align*}, but that’s not the best option. Here it is typeset with {align*}:

Three columns of equations, aligned at equals signs, but spread too widely across the width of the page.

The {align*} environment distributed the available horizontal white space evenly around the columns of equations. That might sound like a reasonable choice, but often the results of {align*} are not desirable aesthetically.

With {alignat} and {alignat*}, you get to choose the horizontal spacing according to what’s best aesthetically or according to other needs (for instance, you might have a reason to have some “columns” closer together than others). Between columns of equations, a \quad typically looks good.

How to {alignat}
#

Here is one way to generate the {alignat*} version of our example:

\begin{alignat*}{3}
3a+4b&=5,\quad& c-d&=4,\quad& 4x+5y&=7,
\\
a-b&=9,\quad& 6c+8d&=3,\quad& 9x-24y&=0
\end{alignat*}

As with the {align} and {align*} environments, ampersands in the code separate the contents of alternately right- and left-aligned boxes. It can be helpful to think of each pair of right- and left-aligned boxes as belonging to a “column”, such as a column of equations, as in our example.

Unlike the {align} and {align*} environments, {alignat} and {alignat*} each take an argument specifying the maximum number of right- and left-aligned pairs per line. In our example, the value of that argument is three, so each line can have at most three such pairs, and the maximum number of ampersands per line is five (five ampersands will separate six boxes).

The {align} and {align*} environments add space around the columns (even if a column is entirely empty), distributing the space evenly across the width of the page. The {alignat} and {alignat*} environments do not add any such space. As noted earlier, the spacing is up to you.

Some food for thought: Not all four instances of \quad in the code above are necessary to generate an identical result. Which two suffice? You might want to chew that over while watching the video below.

When to {alignat}
#

Though displaying multiple columns of equations might be the most obvious use of {alignat} or {alignat*}, it’s not the only one. For instance, these environments can also be useful for placing explanations within a display. The video below includes such an example, along with some general discussion of {alignat*}.

Watch the video
#

Further reading
#

User’s guide for the amsmath package


Header image by Photos of Korea, available from Unsplash. Free to use under the Unsplash license.

Typesetting TeXniques - This article is part of a series.
Part 8: This Article