1

I would like to align the first "+" in the third and fourth lines of the following code. In the third line, I have "= 3 + [a mess]" and in the fourth line, I have "+ [another mess]" - I don't have the "3" in the fourth line. I used the \hphantom command to account for the horizontal space of the "= 3" in the third line, but there is a small space, the space that surrounds either side of a binary operator - in this case a plus sign - that needs to be inserted. (I am using 10pt font in amsart.) Here is the code :

\begin{align*}
&\vert xy + xz + yz \vert^{2} \\
&\qquad = [\cos(a + b) + \cos(a + c) + \cos(b + c)]^{2}
+ [\sin(a + b) + \sin(a + c) + \sin(b + c)]^{2} \\
&\qquad = 3 + [2\cos(a + b)\cos(a + c)
+ 2\cos(a + b)\cos(b + c)
+ 2\cos(a + c)\cos(b + c)] \\
&\qquad \hphantom{= 3} + [2\sin(a + b)\sin(a + c)
+ 2\sin(a + b)\sin(b + c)
+ 2\sin(a + c)\sin(b + c)] .
\end{align*}

I tried using a \phantom command with a \mathbin{+} command, but that added the horizontal space of the plus sign to the fourth line. I tried to put another align environment within the given align environment.

1
  • 1
    \hphantom{{}= 3}
    – LaRiFaRi
    Jul 16, 2014 at 15:02

3 Answers 3

2

It is enough to used an aligned[t] environment inside align. The [t option is to have the aligned environmant aligned by its top line; And youi don't nee all thase manually inserted \qquads to shift the first line with respect to the following: the mathtools package (which loads amsmath) has a \MoveEqLeft command for that: it takes an optional argument, the number of em's you want to move it (2 by default). It replaces the & on the first line.

But maybe you'll find using multlined instead will look as nice. I give an example of both solutions:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{amssymb,mathtools}
\usepackage{amsfonts}
\begin{document}

\begin{align*}    
\MoveEqLeft[3]\vert xy + xz + yz \vert^{2} \\
& = [\cos(a + b) + \cos(a + c) + \cos(b + c)]^{2}
+ [\sin(a + b) + \sin(a + c) + \sin(b + c)]^{2} \\
    & = \begin{aligned}[t]3  & + [2\cos(a + b)\cos(a + c)
    + 2\cos(a + b)\cos(b + c)
    + 2\cos(a + c)\cos(b + c)] \\
    & + [2\sin(a + b)\sin(a + c)
    + 2\sin(a + b)\sin(b + c)
    + 2\sin(a + c)\sin(b + c)] .
    \end{aligned}
\end{align*}



\begin{align*}
\MoveEqLeft[3]\vert xy + xz + yz \vert^{2} \\
& = [\cos(a + b) + \cos(a + c) + \cos(b + c)]^{2}
+ [\sin(a + b) + \sin(a + c) + \sin(b + c)]^{2} \\
    & = \begin{multlined}[t]3  + [2\cos(a + b)\cos(a + c)
    + 2\cos(a + b)\cos(b + c)
    + 2\cos(a + c)\cos(b + c)] \\
     + [2\sin(a + b)\sin(a + c)
    + 2\sin(a + b)\sin(b + c)
    + 2\sin(a + c)\sin(b + c)] .
    \end{multlined}
\end{align*}
\end{document} 

enter image description here

2
  • To use the "\MoveEqLeft[3]" command, I had to add "usepackage{mathtools}" to the preamble. Do you know a web site that explains some of the commands available in this package? You have the optional argument "[3]" to move the first line 3 em's to the left. Do you know how many em's is equal to \quad or \qquad? Please explain " The [t] option is to have the aligned environment aligned by its top line." I posted a similar question about alignment. The tag is "Alignment in aligned and aligned[t] environments." Your comments would be appreciated.
    – user143462
    Jul 16, 2014 at 19:20
  • Yes it was written in my preamble. Don't load amsmath in that case: it loads it (mathtools is an extension of amsmath; multlined also is defined in mathtools). quad is \ hspace 1em, and \qquad of course is 2. As for the t option, try without it (=c option) and with b, you'll understand at once.
    – Bernard
    Jul 16, 2014 at 19:33
0

Instead of indenting I usually outdent the first term and align on the right of the =

\documentclass[a4paper]{memoir}
\usepackage{amsmath,amssymb,mathtools}
\DeclarePairedDelimiter\abs\lvert\rvert
\begin{document}

\begin{align*}
  \MoveEqLeft[3] \abs{xy + xz + yz}^{2}
  \\
  = {} & [\cos(a + b) + \cos(a + c) + \cos(b + c)]^{2}
  \\
  &+ [\sin(a + b) + \sin(a + c) + \sin(b + c)]^{2}
  \\
  ={} & 3
  \! % special feature
  \begin{aligned}[t]
    &+
    \!% special feature
    \begin{aligned}[t]
      [&2\cos(a + b)\cos(a + c) + 2\cos(a + b)\cos(b +
      c) \\
      &+ 2\cos(a + c)\cos(b + c)]
    \end{aligned}
    \\
    & +
    \!
    \begin{aligned}[t] 
      [&2\sin(a + b)\sin(a + c) + 2\sin(a + b)\sin(b +
      c) \\
      &+ 2\sin(a + c)\sin(b + c)] .
    \end{aligned}
  \end{aligned}
\end{align*}

\end{document}

enter image description here

0
% arara: pdflatex

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align*}
\vert xy + xz + yz \vert^{2} &= [\cos(a + b) + \cos(a + c) + \cos(b + c)]^{2}\\
&\quad+ [\sin(a + b) + \sin(a + c) + \sin(b + c)]^{2} \\
&= 3 + [2\cos(a + b)\cos(a + c)\\
&\phantom{{}= 3} \quad + 2\cos(a + b)\cos(b + c)
+ 2\cos(a + c)\cos(b + c)] \\
&\phantom{{}= 3} + [2\sin(a + b)\sin(a + c)\\
&\phantom{{}= 3} \quad  + 2\sin(a + b)\sin(b + c)
+ 2\sin(a + c)\sin(b + c)]
\end{align*}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .