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.

I have a long equation in LaTeX, which I need to break up into more lines. I've done this, although its not quite what I was looking for. Here is a MWE showing my problem:

\documentclass[10pt]{article}

\usepackage[T1]{fontenc}
\usepackage{amsmath, amsthm, amssymb}
\usepackage[ansinew]{inputenc}

\begin{document}
\begin{equation}
  \begin{aligned}
        \alpha &= 1 &&+ 2     \\
               &    &&- 3 + 4 \\
               &= 4 \\
               &=5-1,
  \end{aligned}
\end{equation}
\end{document}

So there is a long equation broken into 2 lines, followed by 2 short lines. Here is what I desire:

  1. There should be an equation label for each equality sign, so 3 in total. At the moment there is only one

  2. The "+2" and "-3+4"-parts are aligned right, which distorts the whole equation. I'm not quite sure why it is doing that, I haven't told it explicitly to do so.

Is there a way to correct these errors?


EDIT: Original output looks like

Original output

share|improve this question
1  
Welcome to TeX.sx! Your question was migrated here from another stackexchange site. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Marco Daniel Oct 1 '12 at 3:08
    
I'd want to point to Heiko Oberdiek's answer to another question. This would work in this (simple) problem, too: \SP after the 1 and \UP in front of the -3. –  Qrrbrbirlbel Oct 1 '12 at 5:12
add comment

migrated from stackoverflow.com Oct 1 '12 at 3:06

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 10 down vote accepted

Instead of aligned, I would suggest an align environment; \notag can be used to suppress the tag for selected lines; the alignment for the second line can be produced with the help of a \phantom:

\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath, amsthm, amssymb}
\usepackage[ansinew]{inputenc}

\begin{document}
\begin{align}
\alpha &= 1 + 2     \\
&\phantom{{}=1}-3 + 4 \notag\\
&= 4 \\
&=5-1,
\end{align}

\end{document}

enter image description here

share|improve this answer
    
I'd use & \hphantom{{} = 1} - 3 … so that = is treated as a relation (the \?phantom works as an ordinary object for the ). –  Qrrbrbirlbel Oct 1 '12 at 3:59
    
@Qrrbrbirlbel yes, you're right. I updated my answer. Thank you. –  Gonzalo Medina Oct 1 '12 at 4:27
    
Thanks, a very nice approach! –  BillyJean Oct 1 '12 at 16:39
add comment
  1. There should be an equation label for each equality sign, so 3 in total. At the moment there is only one

By using equation and the sub-environment aligned, you told it to generate only one equation number for the entire block. To get an equation number for each line, you can use for example the align environment. You can suppress equation numbers for any line therein with the \nonumber command. Alternatively, you can get vertically centered equation numbers for broken equations by using the split sub-environment for these.

Using split unfortunately has the problem that you need manual spacing to align the second part of the broken equation as desired, but if you only want it to be indented enough to clearly indicate it's a continuation of the line above, a \qquad produces good results.

\documentclass[10pt]{article}

\usepackage[T1]{fontenc}
\usepackage{amsmath, amsthm, amssymb}
\usepackage[ansinew]{inputenc}

\begin{document}
\begin{align}
  \begin{split}
        \alpha &= 1 + 2     \\
               & \qquad   - 3 + 4
   \end{split} \\
               &= 4 \\
               &=5-1,
\end{align}
\end{document}

produces something that to me looks good.

  1. The "+2" and "-3+4"-parts are aligned right, which distorts the whole equation. I'm not quite sure why it is doing that, I haven't told it explicitly to do so.

You did. I'm not 100% sure how exactly align and alignment interpret multiple & markers, but as far as I can tell, they cause alternating right- and left-alignment in each column, so your code placed them left-aligned in the rightmost of four columns. You can push them further left by adding some hspace* after any of the two parts, but that will not push them further left than the right end of any other second column in the environment.

I recommend align and split.


EDIT: The aforementioned code looks like

output of code example

share|improve this answer
add comment

I always use the alignat environment for that.
I used \notag to have no equation number in the first line.

Code

\documentclass[10pt]{article}

\usepackage[T1]{fontenc}
\usepackage{amsmath, amsthm, amssymb}
\usepackage[ansinew]{inputenc}

\begin{document}
  \begin{alignat}{2}
    \alpha & = 1 && {} + 2 \notag \\
           &     && {} - 3 + 4    \\
           & = 4 &&               \\
           & = 5 - 1
  \end{alignat}
\end{document}

Output

compiled code

share|improve this answer
1  
To me, this doesn't look good at all with the excessive space on line 1. –  mrf Oct 1 '12 at 13:40
    
@mrf I mimicked the spacing from the questioner's original output. If you want the + 2 and the – 3 spaced like the – 1, just use align or split and & \hphantom{{} = 1} - 3 + 4 for the second line. –  Qrrbrbirlbel Oct 1 '12 at 13:49
    
What is the diff between \phantom and \hphantom? –  I am who I say I am Oct 21 '13 at 10:41
    
@Marienplatz \hphantom only includes a rule with the width of the content to \hphantom, \vphantom only height + depth. \phantom both. In this example, there will be no difference between \phantom and \hphantom but try with \frac{1}{2} instead of 1. –  Qrrbrbirlbel Oct 22 '13 at 1:51
    
OK. I see. Thank you! –  I am who I say I am Oct 22 '13 at 7:15
add comment

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.