The following code has three alignments in an alignat environment. I am displaying equivalent expressions for $\vert xy + xz + yz \vert$ and for $\vert x + y + z \vert$. I want all the "=" to be aligned. They are. I want the first "+" in lines 1, 2, and 5 after $\vert xy + xz + yz \vert$ to be aligned with each other and with the first "+" in lines 2, 3, 4, 5 and 7 after $\vert x + y + z \vert$. Most of them are aligned. The first "+" in lines 2 and 3 after $\vert x + y + z \vert$ are slightly off due to the unseemly short space between the "+" and the "[". Why is the spacing not appropriate in these two lines? Why are all these "+" artificially shifted rightward? Do I have to insert an empty space "{}" to the left of the "+" in these lines to get the appropriate space? In another post, someone suggested using the "\mathrlap" command to get proper alignment. It gave me the proper alignment in that post. I don't know what it does, and so I don't know how to adapt it for this new code. I thought that it meant to make a box of no width and to put the text to the right of it. Is that right? (The third alignment is correct.)
\documentclass[10pt]{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{mathtools}
\usepackage{tikz}
\begin{document}
\begin{alignat*}{3}
\MoveEqLeft[2] \vert xy + xz + yz \vert^{2} \\
&= 3 &&+ \bigl[&&\cos(2a + b + c) + \cos(a + 2b + c) + \cos(a + b + 2c) \\
&&&&&+ \cos(a - b) + \cos(a - c) + \cos(b - c)\bigr] \\
&&&+ \bigl[&&\cos(a - b) + \cos(a - c) + \cos(b - c) \\
&&&&&- \bigl(\cos(2a + b + c) + \cos(a + 2b + c) + \cos(a + b + 2c)\bigr) \bigr] \\
&= 3&&\mathrlap{{}+ 2\bigl(\cos(a - b) + \cos(a - c) + \cos(b - c)\bigr).}
\intertext{Likewise,}
\MoveEqLeft[2] \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}
Best Answer
I guess you are looking for the following layout
Change
to
Then
\abs{xy + xz + yz}^{2}
is set in a2em
width mathbox.Code:
All
align...
environments work like tables with a couple ofrl
column pairs. The&
have a similar meaning as in tables.Here is a picture to show how
\mathmakebox[2em][l]{...}
and\mathrlap{...}
work.There are three
rl
column pairs. Because the second and the thirdr
column is completely empty their column width in thealignat*
environment is 0pt.The green boxes show the real width of the arguments of
\(math)makebox[2em][l]{...}
in the first line and\(math)rlap{...}
in the last line. But the red boxes show the used width for this boxes: in the first line2em
and in the last line0pt
(and of course the width of the red lines) . The additional width of the contents is simple ignored and does not influence the width of the columns.In the following picture you can see what happens if
\(math)makebox[2em][l]{...}
and\(math)rlap{...}
are removedCode for the first picture: