44

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

migrated from stackoverflow.com Oct 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
48

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

  • Can you explain the {} at the beginning of the \phantom command? – Bach May 14 '18 at 7:18
  • Beautifully engineered ;). Sad, there is no automatic option for line breaking a sub-equation. – loved.by.Jesus Jul 1 '18 at 18:51
  • 1
    @Bach It makes the = become a relationship operator (to get proper spacing) by giving it a LHS (left-hand side). – Solomon Ucko Dec 29 '18 at 16:05
9
  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

4

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

  • 2
    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? – kiss my armpit 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
0
\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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.