0

The following code almost gives me the alignment that I want. You will see that in the last five lines of the displayed equations, most of the expressions are ridiculously shifted rightward. I want the first "+" in these lines to be aligned with the first "+" in lines 2 and 3. Thanks.

\documentclass[10pt]{amsart}
\usepackage{}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{mathtools}
\usepackage{tikz}

\begin{document}
\begin{alignat*}{3}
\vert x + y + z \vert^{2}
&= [\cos{a} + \cos{b} + \cos{c}]^{2} + [\sin{a} + \sin{b} + \sin{c}]^{2} \\
&= \begin{aligned}[t] 3 &+ [2\cos{a}\cos{b} + 2\cos{a}\cos{c} + 2\cos{b}\cos{c}] \\
&+ [2\sin{a}\sin{b} + 2\sin{a}\sin{c} + 2\sin{b}\sin{c}]
\end{aligned} \\
&= 3&& + \bigl[&&\cos(a + b) + \cos(a + c) + \cos(b + c) \\
  &&&&&+ \cos(a - b) + \cos(a - c) + \cos(b - c)\bigr] \\
  &&&+ \bigl[&&\cos(a - b) + \cos(a - c) + \cos(b - c) \\
  &&&&&- \bigl(\cos(a + b) + \cos(a + c) + \cos(b + c)\bigr) \bigr] \\
  &= 3&&\mathrlap{{}+ 2\bigl(\cos(a - b) + \cos(a - c) + \cos(b - c)\bigr).}
\end{alignat*}

\end{document}
user143462
  • 1,039

2 Answers2

1

As far as I understand, you want to obtain the following (Oh!):

\documentclass[10pt]{amsart}
\usepackage{}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{mathtools}
\usepackage{tikz}

\begin{document}
\begin{alignat*}{3}
\vert x + y + z \vert^{2}
&= [\cos{a} + \cos{b} + \cos{c}]^{2} + [\sin{a} + \sin{b} + \sin{c}]^{2} \\
&= \begin{aligned}[t] 3 &+ [2\cos{a}\cos{b} + 2\cos{a}\cos{c} + 2\cos{b}\cos{c}] \\
&+ [2\sin{a}\sin{b} + 2\sin{a}\sin{c} + 2\sin{b}\sin{c}]
\end{aligned}\\ 
&= \begin{aligned}[t]3 &+ \bigl[\cos(a + b) + \cos(a + c) + \cos(b + c) \\
 & + \cos(a - b) + \cos(a - c) + \cos(b - c)\bigr] \\
  &+ \bigl[\cos(a - b) + \cos(a - c) + \cos(b - c) \\
  &- \bigl(\cos(a + b) + \cos(a + c) + \cos(b + c)\bigr) \bigr] \\
\end{aligned} \\
  &= 3\mathrlap{{}+ 2\bigl(\cos(a - b) + \cos(a - c) + \cos(b - c)\bigr).}
\end{alignat*}

\end{document}

enter image description here

I am not sure, if the last line should look a bit different, as it is suggested by your example, but I have left it untouched. However,Iwould suggest the following version:

\documentclass[10pt]{amsart}
\usepackage{}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{mathtools}
\usepackage{tikz}

\begin{document}
\begin{alignat*}{3}
\vert x + y + z \vert^{2}
&= [\cos{a} + \cos{b} + \cos{c}]^{2} + [\sin{a} + \sin{b} + \sin{c}]^{2} \\
&= \!\begin{aligned}[t] 3 &+ [2\cos{a}\cos{b} + 2\cos{a}\cos{c} + 2\cos{b}\cos{c}] \\
&+ [2\sin{a}\sin{b} + 2\sin{a}\sin{c} + 2\sin{b}\sin{c}]
\end{aligned}\\ 
&=\! \begin{aligned}[t]3 &+ \bigl[\cos(a + b) + \cos(a + c) + \cos(b + c) \\
 & + \cos(a - b) + \cos(a - c) + \cos(b - c)\bigr] \\
  &+ \bigl[\cos(a - b) + \cos(a - c) + \cos(b - c) \\
  &- \bigl(\cos(a + b) + \cos(a + c) + \cos(b + c)\bigr) \bigr] \\
\end{aligned} \\
%  &= 3\mathrlap{{}+ 2\bigl(\cos(a - b) + \cos(a - c) + \cos(b - c)\bigr).}
 &= 3{{}+ 2\bigl(\cos(a - b) + \cos(a - c) + \cos(b - c)\bigr).}
\end{alignat*}

\end{document}

enter image description here

1

With reference to your previous question:

You can use \mathrlap also in the first three lines.

\documentclass[10pt]{amsart}
\usepackage{mathtools}% loads also amsmath

\begin{document}

\begin{alignat*}{3}
  \vert x + y + z \vert^{2}
    &= \mathrlap{[\cos{a} + \cos{b} + \cos{c}]^{2} + [\sin{a} + \sin{b} + \sin{c}]^{2}} \\
  &= 3 &&\mathrlap{{}+ [2\cos{a}\cos{b} + 2\cos{a}\cos{c} + 2\cos{b}\cos{c}]} \\
  &&&\mathrlap{{}+ [2\sin{a}\sin{b} + 2\sin{a}\sin{c} + 2\sin{b}\sin{c}]}\\
  &= 3&& + \bigl[&&\cos(a + b) + \cos(a + c) + \cos(b + c) \\
  &&&&&+ \cos(a - b) + \cos(a - c) + \cos(b - c)\bigr] \\
  &&&+ \bigl[&&\cos(a - b) + \cos(a - c) + \cos(b - c) \\
  &&&&&- \bigl(\cos(a + b) + \cos(a + c) + \cos(b + c)\bigr) \bigr] \\
  &= 3&&\mathrlap{{}+ 2\bigl(\cos(a - b) + \cos(a - c) + \cos(b - c)\bigr).}
\end{alignat*}

\end{document}

Result:

enter image description here

Or you use \mathrlap in only in the first line and aligned for the other lines.

\documentclass[10pt]{amsart}
\usepackage{mathtools}% loads also amsmath

\begin{document}

\begin{alignat*}{2}
  \vert x + y + z \vert^{2}
    &= \mathrlap{[\cos{a} + \cos{b} + \cos{c}]^{2} + [\sin{a} + \sin{b} + \sin{c}]^{2}} \\
  &= 3 &&
    \!\begin{aligned}[t]
      & + [2\cos{a}\cos{b} + 2\cos{a}\cos{c} + 2\cos{b}\cos{c}] \\
      &+ [2\sin{a}\sin{b} + 2\sin{a}\sin{c} + 2\sin{b}\sin{c}]
    \end{aligned} \\
  &= 3&&
    \!\begin{aligned}[t]
      {}+ \bigl[&\cos(a + b) + \cos(a + c) + \cos(b + c) \\
      &+ \cos(a - b) + \cos(a - c) + \cos(b - c)\bigr]
    \end{aligned} \\
  &&&
    \!\begin{aligned}[t]
      {}+ \bigl[&\cos(a - b) + \cos(a - c) + \cos(b - c) \\
      &- \bigl(\cos(a + b) + \cos(a + c) + \cos(b + c)\bigr) \bigr]
    \end{aligned}\\
  &= 3&&+ 2\bigl(\cos(a - b) + \cos(a - c) + \cos(b - c)\bigr).
\end{alignat*}

\end{document}

Resultat:

enter image description here

The \! in front of \begin{aligned}[t] is necessary because aligned inserts a \,

esdd
  • 85,675
  • This is exactly the displayed equations that I wanted! I used your first code. Thanks. Why was my original code instructing LaTeX to shift the expressions, except for the 3, awkwardly to the right? I guess that having only one "&" in the first line has something to do with it. How does "\mathrlap" avoid this? (I know that it puts a box of width 0 about the expression that got awkwardly shifted.) I didn't know that alignments could be set in subsequent lines. That is useful. – user143462 Jul 17 '14 at 15:29
  • I read the explanations about amsmath putting a thinspace - "," - in front of the aligned and gathered environments. It seems that a thinspace was designed to be inserted before these environments in amstex, and when Michael Spivak adapted amsmath from amstex, he kept this feature. It is strange that the same space is not inserted after these environments to keep them centered. The amstex didn't have it, and Spivak missed it when developing his amsmath. So, now we have to remember to add "!" before these environments to avoid adding artificial blank space and to keep things centered. – user143462 Jul 17 '14 at 15:51