173

My equation is very long. How do I get it to continue on the next line rather than go off the page?

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
ubutu
  • 1,731
  • 2
  • 11
  • 3
  • I would question if you really want to do that. Multi-line equations will be very difficult to read. Is it possible to break up your equation into multiple (shorter) equations? – pkaeding May 18 '10 at 18:58
  • Use \notag \\ Check relevant answers here: https://tex.stackexchange.com/questions/74819/aligned-equations-in-latex – user2060802 Oct 16 '20 at 10:23

13 Answers13

161

If your equation does not fit on a single line, then the multline (note that that's multline without an "i", not "multiline") environment probably is what you need:

\begin{multline}
    first part of the equation \\
    = second part of the equation
\end{multline}

If you also need some alignment respect to the first part, you can use split:

\begin{equation}
    \begin{split}
        first part &= second part #1 \\
        &= second part #2
    \end{split}
\end{equation}

Both environments require the amsmath package.

See also aligned as pointed out in an answer below.

Jack M
  • 4,769
  • 6
  • 43
  • 67
Alessandro Cuttin
  • 3,822
  • 1
  • 30
  • 36
25

Not yet mentioned here, another choice is environment aligned, again from package amsmath:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation}
  \begin{aligned}
    A & = B + C\\
      & = D + E + F\\
      & = G
  \end{aligned}
\end{equation}

\end{document}

This outputs:

screenshot of output (detail)

MattAllegro
  • 6,455
  • 5
  • 45
  • 52
13

Without configuring your math environment to clip, you could force a new line with two backslashes in a sequence like this:

Bla Bla \\ Bla Bla in another line

The problem with this is that you will need to determine where a line is likely to end and force to always have a line break there. With equations, rather than text, I prefer this manual way.

You could also use \\* to prevent a new page from being started.

Uri
  • 88,451
  • 51
  • 221
  • 321
10

If it is inline equation, then use \allowbreak. Use it like:

$x_1,x_2,x_3,\allowbreak x_4,x_5$.

Latex will break equation in this place only if necessary.

MattAllegro
  • 6,455
  • 5
  • 45
  • 52
HD2000
  • 144
  • 1
  • 8
6

There are a couple ways you can deal with this. First, and perhaps best, is to rework your equation so that it is not so long; it is likely unreadable if it is that long.

If it must be so, check out the AMS Short Math Guide for some ways to handle it. (on the second page)

Personally, I'd use an align environment, so that the breaking and alignment can be precisely controlled. e.g.

\begin{align*}
   x&+y+\dots+\dots+x_100000000\\
   &+x_100000001+\dots+\dots
\end{align*}

which would line up the first plus signs of each line... but obviously, you can set the alignments wherever you like.

jcastrov
  • 68
  • 2
  • 9
TJ Ellis
  • 615
  • 3
  • 10
6

I used the \begin{matrix}

\begin{equation}
\begin{matrix}
    line_1 \\ 
    line_2 \\ 
    line_3
\end{matrix}
\end{equation}
5

I think I usually used eqnarray or something. It lets you say

\begin{eqnarray*}
    x &=& blah blah blah \\ 
      & & more blah blah blah \\
      & & even more blah blah
\end{eqnarray*}

and it will be aligned by the & &... As pkaeding mentioned, it's hard to read, but when you've got an equation thats that long, it's gonna be hard to read no matter what... (The * makes it not have an equation number, IIRC)

Brian Postow
  • 11,709
  • 17
  • 81
  • 125
  • 4
    f.y.i. the AMS recommends not using eqnarray environments because they "produce inconsistent spacing of the equal signs and make no attempt to prevent overprinting of the equation body and equation number." -- not really applicable here, but good to know; a good ol' align environment can take care of most such circumstances. – TJ Ellis May 18 '10 at 21:01
  • Is there a way to make this one number the equation also? If I insert a label, I can reference it by number, but it's not printed on the right side of the equation. – henrikstroem Oct 04 '17 at 21:11
4

multline is best to use. Instead, you can use dmath, split as well.

Here is an example:

\begin{multline}
  {\text {\bf \emph {T(u)}}} ={  \alpha *}{\frac{\sum_{i=1}^{\text{\bf \emph {I(u)}}}{{\text{\bf \emph {S(u,i)}}}* {\text {\bf \emph {Cr(P(u,i))}}} * {\text {\bf \emph {TF(u,i)}}}}}{\text {\bf \emph {I(u)}}}}  \\
   +{  \beta *}{\frac{\sum_{i=1}^{\text{\bf \emph {$I_h$(u)}}}{{\text{\bf \emph {S(u,i)}}}* {\text {\bf \emph {Cr(P(u,i))}}} * {\text {\bf \emph {TF(u,i)}}}}}{\text {\bf \emph {$I_h$(u)}}}}
\end{multline}
Dune
  • 75
  • 5
NarasimhaTejaJ
  • 1,427
  • 2
  • 11
  • 9
3

This worked for me while using mathtools package.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
    \begin{equation}
        \begin{multlined}
            first term \\
            second term                 
        \end{multlined}
    \end{equation}
\end{document}
Mukesh Chapagain
  • 25,063
  • 15
  • 119
  • 120
2

Use eqnarray and \nonumber

example:

\begin{eqnarray}
    sample = R(s,\pi(s),s') + \gamma V^{\pi} (s') \nonumber \\
    \label{eq:temporal-difference}
     V^{\pi}_{k+1}(s) = (1-\alpha)V^{\pi}(s) - \alpha[sample]
\end{eqnarray}
Amir Hossein Jamsidi
  • 1,980
  • 1
  • 18
  • 10
1

SIMPLE ANSWER HERE

\begin{equation}
\begin{split}

equation \\
here

\end{split}
\end{equation}
Cyril
  • 2,783
  • 1
  • 24
  • 35
1

You do not need any extra package to do this:

\begin{equation}
  \begin{gathered}
     first formula\\
     second formula
  \end{gathered}
\end{equation}
0

To solve this issue, I used the array environment inside the equation environment like this:

\begin{equation}
    \begin{array}{r c l}
       first Term&=&Second Term\\
                 &=&Third Term
    \end{array}
\end{equation}