# Aligned equations in LaTeX

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{aligned} \alpha &= 1 &&+ 2 \\ & &&- 3 + 4 \\ &= 4 \\ &=5-1, \end{aligned}
\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

-

## migrated from stackoverflow.comOct 1 '12 at 3:06

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

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

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}


-
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
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

-

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

-
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? –  please stop stalking 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
\documentclass{article}
\def\eqalign#1{\null\,\vcenter{\openup\jot\mathsurround\dimen12
\ialign{\strut\hfil$\textstyle{##}$&$\textstyle{{}##}$\hfil
\crcr#1\crcr}}\,}
\begin{document}
\def\T{\mskip33mu} \eqalign{\alpha &= 1 + 2 \cr & \T - 3 + 4 \cr &= 4 \cr &= 5 - 1, }
\end{document}

-
It would nice if an output is generated for completeness. –  Jesse Nov 20 '14 at 2:02