# How the \alignat works in ams package

I have read the related question(Difference between align and alignat environments), which had detailed answer but still don't know what the meaning of the \alignat's argument. It is said in http://people.cs.uchicago.edu/~ivan/math/amsldoc.pdf that

This environment takes one argument, the number of “equation columns”: count the maximum number of &s in any row, add 1 and and divide by 2.

What is the meaning of adding one in & number and divide by two? I presumed the argument is given by the user, not automatically generated by the system?

• \begin{alignat}{3} means you want three pairs of “right-left columns”. Hence you need five & as separator between the total six columns. – egreg Jan 18 '18 at 18:31
• @Rikeijin: Another way to explain (which I find more illuminating) is that every column of alignments, except the first, has to be introduced by an &, and thaat inside each column the alignment point has to be specified by another &. For n columns, this makes 2n – 1 &. – Bernard Jan 18 '18 at 19:27

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.

• I cannot choose both reply as accepted answer but both are great answer! – Rikeijin Jan 18 '18 at 18:59
• @Rikeijin: Once you have the privilege to vote, you can vote to show support. It's different from accepting an answer. – Werner Jan 18 '18 at 19:03