# Aligning several '=' symbols across two lines

I'd like to write two lines of equations, each containing two '=' symbols, in such a way that the corresponding '=' symbols will be vertically aligned.

I tried using the align environment thus:

\begin{align*}
P^{-1}AP & = P^T\left[\lambda_1p_1, \dots, \lambda_np_n\right] & = \left[\lambda_1P^Tp_1, \dots, \lambda_nP^Tp_n\right]
\\ & = \left[\lambda_1i_1, \dots, \lambda_ni_n\right] & = \textrm{diag}\left(\lambda_1, \dots, \lambda_n\right)
\end{align*}


But this produced this output where the second '=' symbols are not aligned. Why aren't they aligned? How can I align them?

-

The alignat* environment does it for you with two alignment characters (&) in front of the equal signs.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\begin{document}
\begin{alignat*}{2}
P^{-1}AP & = P^T\left[\lambda_1p_1, \dots, \lambda_np_n\right] && = \left[\lambda_1P^Tp_1, \dots, \lambda_nP^Tp_n\right] \\
& = \left[\lambda_1i_1, \dots, \lambda_ni_n\right] && = \textrm{diag}\left(\lambda_1, \dots, \lambda_n\right)
\end{alignat*}
\end{document}


For comparison without automatically scaled delimiters and "diag" as operator.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\DeclareMathOperator*{\diag}{diag}

\begin{document}
\begin{alignat*}{2}
P^{-1}AP &= P^T [\lambda_1p_1, \dots, \lambda_np_n] &&= [\lambda_1P^Tp_1, \dots, \lambda_nP^Tp_n] \\
&= [\lambda_1i_1, \dots, \lambda_ni_n] &&= \diag(\lambda_1, \dots, \lambda_n)
\end{alignat*}
\end{document}


-
It would be better if you removed the useless \left and \right and turned \textrm{diag} into \operatorname{diag}. –  egreg Mar 4 '14 at 9:08
@egreg: These are not my idea and just copied from the question. And by the way, they can also be found in the other answer. The same applies to "diag". Your comment would be more appropriate to the question. –  Thorsten Donig Mar 4 '14 at 9:11
@egreg: Why are the \left and \right useless? Do they have any cons? What would be a suitable circumstance to use them? –  Evan Aad Mar 4 '14 at 9:19
@EvanAad They just add unwanted space, and slightly increase the size in the part above “diag”, which unbalances the display. –  egreg Mar 4 '14 at 9:21
@EvanAad then use mleftright package (see documentation). –  Manuel Mar 4 '14 at 10:31

You need two &. The first of the two is for the left part (here empty) of the second equation system:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
P^{-1}AP & = P^T\left[\lambda_1p_1, \dots, \lambda_np_n\right] && =
\left[\lambda_1P^Tp_1, \dots, \lambda_nP^Tp_n\right]
\\
& = \left[\lambda_1i_1, \dots, \lambda_ni_n\right] && =
\textrm{diag}\left(\lambda_1, \dots, \lambda_n\right)
\end{align*}
\end{document}


-