6

It was my understanding that the argument of alignat was the number of columns, and that we use & to separate them. I tried the following code:

\begin{alignat*}{3}
   \quad    & P_{2}(x) &= (2)(2x-1)(x-1)-20x(x-1)+4x(2x-1)\\
   \implies & \quad    &= \boxed{-8x^{2}+10x+2}
\end{alignat*}

which has three visible columns. However, this doesn't work and produces weird spacings. Tinkering around, I found that the following codes achieves the look I originally wanted (the only difference being the double &&):

\begin{alignat*}{3}
    \quad    & P_{2}(x) &&= (2)(2x-1)(x-1)-20x(x-1)+4x(2x-1)\\
    \implies & \quad    &&= \boxed{-8x^{2}+10x+2.}
\end{alignat*}

What am I misunderstanding here?

campa
  • 31,130
Alex D
  • 225
  • 4
    Three alignment columns require 5 ampersands (one for each column but the first, and one for the alignment point inside each column). – Bernard Nov 25 '20 at 12:21

1 Answers1

3

How the number of columns works

As stated in amsmath's documentation (pp. 8),

A variant environment alignat allows the horizontal space between equations to be explicitly specified. This environment takes one argument, the number of “equation columns” (the number of pairs of right-left aligned columns; the argument is the number of pairs): count the maximum number of &s in any row, add 1 and divide by 2.

How the alignment works

Each equation column is aligned on one &, and separated from the next one by another &. Another way of saying this is that, if you think of your environment as an array, the columns of the array are alternatively right- and left-aligned. This is somewhat weird to explain because one has to distinguish between “equation columns” and columns of the environment if you think of it as an array. A pair of these array columns makes an equation column.

Back to your examples

Here's the alignat environment from your first example.

\begin{alignat*}{3}
   \quad    & P_{2}(x) &= (2)(2x-1)(x-1)-20x(x-1)+4x(2x-1)\\
   \implies & \quad    &= \boxed{-8x^{2}+10x+2}
\end{alignat*}

Here you specify three equation columns, but only two are in fact used: one for the \implies, and one where the equalities are placed. Indeed, you use three &s, so using the computation from to the documentation we get two columns.

The first equation column is only, schematically,

   \quad P_{2}(x)
\implies \quad

It is aligned on the left of P_{2}(x) and on the right of the \implies. On each row, the second & separates the first equation column from the next one, which is only

= (2)(2x-1)(x-1)-20x(x-1)+4x(2x-1)
= \boxed{-8x^{2}+10x+2}

and which is aligned on the right, since it is the first part of a pair which makes an equation column.

Your second example is exactly the same, except that the second equation column is now aligned on the equal sign, since the equations are placed on the second part of the pair which makes the whole equation column, the first part being empty. The alignment looks good, but in fact only because alignat does not put any space between columns.

I think it would make more sense to place the P_{2}(x) part in the second equation column as well, with only the \implies in the first one.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{2}
   &          & P_{2}(x) &= (2)(2x-1)(x-1)-20x(x-1)+4x(2x-1)\\
   & \implies &          &= \boxed{-8x^{2}+10x+2}
\end{alignat*}
\end{document}

The output is the same as your second example, but the code is indeed more consistent with the content of the equations.

Vincent
  • 20,157