[Tex/LaTex] Multiple alignments

alignhorizontal alignment

If I have a string of equations whose equal signs are aligned and one of the equations is too long and needs to span multiple lines, how do I create a second alignment. For instance, in the following example

\begin{align*}  
  f(x)&=eqn1\\  
      &=eqn2_part1+eqn2_part2\\   
      &           +eqn2_part3\\  
      &=eqn3\\   
      &=eqn4\\  
\end{align*}

How do I align the equals signs and the plus signs.

Best Answer

Using boxes via \phantom is also an option, if alignment characters like && get in the way for long equations:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{align*}  
  f(x)&=\text{eqn}_1\\  
      &=\text{eqn}_2\text{-part}_1+\text{eqn}_2\text{-part}_2\\   
      &\phantom{{}=\text{eqn}_2\text{-part}_1}{}+\text{eqn}_2\text{-part}_3\\  
      &=\text{eqn}_3\\   
      &=\text{eqn}_4\\  
\end{align*}
\end{document}

A correction for the spacing around binary operators ({}+) and relations ({}=) is required though. See Herbert's mathmode document for more on AMS environments and alignment.

Related Question