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.

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.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer

You could use alignat which is also from the amsmath package.

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

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

\end{document}

You'll notice that the alignat environment takes an argument- which is (quoting from the documentation)

the number of “equation columns”: count the maximum number of &s in any row, add 1 and divide by 2.

share|improve this answer
    
When I compile I get a large gap between eqn2_part1 and the plus signs when the length of eqn3 and 4 are longer than eqn2_part1. –  richtera Jun 1 '12 at 16:18
    
@richtera perhaps you could add your code to your question so that folks can play with it? –  cmhughes Jun 1 '12 at 16:31

Please try breqn package. Then use \begin{dmath}...\end{dmath} environment. For example

\documentclass[12pt]{article} %
\usepackage{breqn}
\begin{document}
\begin{dmath}
        g\left[Pr(unrest_{im}=1)\right]=\alpha_{0i}+\alpha_{1}.\left|price\_shock_{im}\right|+\beta.{year}+\gamma.region.\left|price\_shock_{im}\right|+\delta.{region}+\epsilon_{im}

\end{dmath}
\end{document}

enter image description here

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.