Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

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}

Further reading


enter image description here


Addendum

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}

enter image description here

share|improve this answer
2  
It would be better if you removed the useless \left and \right and turned \textrm{diag} into \operatorname{diag}. –  egreg Mar 4 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 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 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 at 9:21
1  
@EvanAad then use mleftright package (see documentation). –  Manuel Mar 4 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}

Result

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.