How the `\alignat` works in ams package

I've always found the description of alignat based on the number of & tokens confusing. It's simpler than that: first you decide how many parts your alignment consists of, then adjust the number of & tokens.

Both align and alignat build tables consisting of pairs of a right aligned column and a left aligned column.

The argument to \begin{alignat} tells how many pairs you want. So, for instance, \begin{alignat}{3} sets things up for a total of six columns (three pairs); therefore the number of & in each line is five.


alignat can also align a single equation, if needed. That is,

\begin{alignat}{1}
  f(x) &= a x^2 + b x + c
\end{alignat}

would yield the same output as

\begin{align}
  f(x) &= a x^2 + b x + c
\end{align}

However, in the above snippet, there is only one &. Any subsequent alignment (or equation column) will require two &s, the first to allow for a right alignment and the second for a left alignment.

So, in general, the number of & + 1 (to double up for the first/left-most alignment) divided by 2 will be equivalent to the number of equation columns.