# Multi-line Equation Problem in Latex

1. Jul 16, 2009

### EngWiPy

Hello,

I have an equation like this one:

$$f(x)=1+g(x)$$

where $$g(x)$$ is a very long term, and I have to split it into two halfs, but I want the second half be exactly under the '+' sign, not under the '=' sign. How can I do that?

Thanks in advance

2. Jul 16, 2009

### KLoux

I think there is some information on this in "The Not So Short Guide to $$\LaTeXe$$." You should be able to google it. I don't remember exactly, but I think you need to use some & to create something like tabs?

Anyway, I'm pretty sure it's in there (Chapter 4?).

-Kerry

EDIT: Actually it's "The Not So Short Introduction to $$\LaTeXe$$." It's available here: http://tobi.oetiker.ch/lshort/lshort.pdf

Last edited: Jul 16, 2009
3. Jul 16, 2009

### sylas

There are quite a number of ways to do things like this, but the "align*" environment makes it easy to do exactly what you describe. Click the following to see code:
\begin{align*} f(x) = 1 & + a + bx + cx^2 \\ & + dx^3 + ex^4 \end{align*}​

Last edited: Jul 16, 2009
4. Jul 16, 2009

### D H

Staff Emeritus
5. Jul 16, 2009

### EngWiPy

Yes, but I need this inside a split enviroment. When I use split alone it is ok, but when I use split inside split, or align inside split enviroment, the equation inside the inner enviroment becomes above and under the '+' sign, and not in the same line. This is exactly my problem.

Regards

6. Jul 16, 2009

### minger

Once your inside the split environment you can simply use ampersands as alignment points.
Code (Text):

\begin{split}
f(x) = 1 &+ \\
&g(x)
\end{split}

$$\begin{split} f(x) = 1 &+ \\ &g(x) \end{split}$$

7. Jul 16, 2009

### EngWiPy

Thank you all for replying, but may be I did not make my point clear, so I will give an example:

$$\begin{split}f(x)=&1+g(x)\\ =&1+\text{Expansion of g(x)} \end{split}$$

the expansion of g(x) spans more than one line, so I want to split it inside a split enviroment. I hope that my point is clear now.

Regards

8. Jul 16, 2009

### Fenn

When I write equations, I like to use a split environment nested within an align environment. To do multiline equations, I do stuff like this:

Code (Text):

\begin{align}\begin{split}
&\rho^s \sum_{k=0}^\infty k(k-1)a_k\rho^{k-2} + 2(s+1)\rho^{s-1}\sum_{k=0}^\infty k a_k\rho^{k-1} - \rho^s \sum_{k=0}^\infty k a_k\rho^{k-1} \newln + (\eta - 1 - s)\rho^{s-1}\sum_{k=0}^\infty a_k\rho^k + [s(s+1) - l(l+1)]\rho^{s-2} \sum_{k=0}^\infty a_k\rho^k = 0
\end{split}\end{align}

where I have defined the \newln command as
Code (Text):

\newcommand{\newln}{\\&\quad\quad{}}

The spacing can be adjusted by putting spacing after the & character. If you need to put a new line inside a parenthesis block ( eg. \left( \right) ), I have another command, \parenthnewln

Code (Text):

\newcommand{\parenthnewln}{\right.\\&\left.\quad\quad{}}

Again, the spacing can be adjusted.

\newcommand{\newln}{\\&\quad\quad{}} \begin{align}\begin{split} &\rho^s \sum_{k=0}^\infty k(k-1)a_k\rho^{k-2} + 2(s+1)\rho^{s-1}\sum_{k=0}^\infty k a_k\rho^{k-1} - \rho^s \sum_{k=0}^\infty k a_k\rho^{k-1} \newln + (\eta - 1 - s)\rho^{s-1}\sum_{k=0}^\infty a_k\rho^k + [s(s+1) - l(l+1)]\rho^{s-2} \sum_{k=0}^\infty a_k\rho^k = 0 \end{split}\end{align}

To fit your example:

\newcommand{\parenthnewln}{\right.\\&\left.\quad\quad{}} \begin{align}\begin{split} f(x) &= 1 + g(x)\\ &= 1 + \left( 1 + x + \frac{x^2}{2} + \parenthnewln + \frac{x^3}{3!} + \ldots \parenthnewln + \frac{x^n}{n!} + \ldots \right) \end{split}\end{align}

9. Jul 17, 2009

### minger

I think I got you. In certain math packages, more than one alignment character "&" is allowed, as long as the same amount are used each line. In this case, you could put one at the equals sign and one at the plus sign . I'm not sure how its treated here, but you could do something like

Code (Text):

\begin{split}
f(x) &= 1 +& g(x) \\
&=1 +& sin(x) + cos(x) + \cdots \\
& +&tan(x)
\end{split}

After preview, its apparent that it is not allowed with the physics forums packages. So, try the other posters suggestion of the align environment, or just break it up into two equations.

Edit: Wait so just to clarify, this isn't what you want?
$$\begin{split} f(x) = 1 +& g(x) \\ =1 +& sin(x) + cos(x) + \cdots \\ +&tan(x) \end{split}$$

10. Jul 17, 2009

### EngWiPy

Thank you both Fenn and minger. Both codes are working well. But I want to ask: in the code that minger gave, the '&' character was not used to align the '=' characters. How is that?

Regards

11. Jul 17, 2009

### Fenn

That alignment example looks very nice in the forums, minger. Which math package allows you to do that? When I use only amsmath in my document, my compiler complains about the multiple alignment tabs per line.

12. Jul 17, 2009

### EngWiPy

Try this one Fenn:

Code (Text):

\begin{split}
f(x)=1+&g(x)\\
=1+&x+x^2+\dots\\
+&x^n
\end{split}
Regards

13. Jul 17, 2009

### minger

It's because I got lucky. Now, there are math packages which allow multiple alignement tabs (I think they're called) per line, as I mentioned, as long as they are the same number per line.

In this case, I simply got lucky because on each line before the + sign, there is only a 1 and an equals sign. It lines up by default really.

14. Jul 17, 2009

### Fenn

Ooh, pretty. Yes, that looks very nice. With my suggestion earlier of defining new commands, it is fairly straightforward to split the equation when it is within parenthesis:

Code (Text):

\newcommand{\parenthnewln}[1]{\right.\\#1&\left.{}}

\begin{split}
f(x)=1+&g(x)\\
=1+&\left(x+x^2+\dots
\parenthnewln{+}x^n+\ldots\right)
\end{split}

$$\newcommand{\parenthnewln}[1]{\right.\\#1&\left.{}} \begin{split} f(x)=1+&g(x)\\ =1+&\left(x+x^2+\dots \parenthnewln{+}x^n+\ldots\right) \end{split}$$

15. Jul 17, 2009

### EngWiPy

We are learning something new each time. Thank you all guys.

16. Jul 18, 2009

### Fenn

One thing I'd like to learn is how to number multiline equations with subindices like (a) (b) (c).

Something like

\begin{align} I = \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix} \end{align} \end{align} \begin{align} f &= ma\\ E &= mc^2\\ \pi &\text{ is exactly three!} \end{align}

What I would like to see in this example, is the first line numbered (1), as it is now, and then the group of three numbered (2a), (2b), (2c).

Does anyone have any suggestions that would accomplish this? I've noticed that the split environment clusters the equations together into one equation number, but that really only helps if I am defining a multi-line equation like where this topic started.

17. Jul 20, 2009

### Fenn

Alright, I found my answer, in case anyone is looking. It's the subequations environment from the amsmath package.

\begin{align} I = \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix} \end{align} \begin{subequations}\begin{align} f &= ma\\ E &= mc^2\\ \pi &\text{ is exactly three!} \end{align}\end{subequations}

18. Jul 20, 2009

### EngWiPy

It is nice Fenn, thank you. I may re-consider the numbering of certain equations based on this.

Regards

19. Jul 21, 2009

### Fenn

I'm now using them for clusters of similar equations, so my index numbers don't get too outrageous.

\begin{subequations}\begin{align} Y_1^{+1}(\theta,\phi) &= -\sqrt{\frac{3}{8\pi}}\sin\theta e^{i\phi} \\ Y_1^0(\theta,\phi) &= \sqrt{\frac{3}{4\pi}}\cos\theta \\ Y_1^{-1}(\theta,\phi) &= \sqrt{\frac{3}{8\pi}}\sin\theta e^{-i\phi} \end{align}\end{subequations}

20. Jul 21, 2009

### minger

\begin{subequations} \begin{align} \frac{u(x_0+\Delta x)-u(x_0)}{\Delta x} &=\frac{du}{dx} + \frac{\Delta x}{2}\frac{d^2 u}{dx^2} +\cdots \\ \frac{u(x_0)-u(x_0-\Delta x)}{\Delta x} &=\frac{du}{dx} - \frac{\Delta x}{2}\frac{d^2 u}{dx^2} +\cdots \\ \frac{u(x_0+\Delta x)-u(x_0-\Delta x)}{\Delta x} &= \frac{du}{dx} + \frac{\Delta x^2}{6}\frac{d^3 u}{dx^3}+ \cdots \end{align} \end{subequations}

Nice!! big fan!

21. May 17, 2011

### sni

Hi Fenn, I tried this but it didn't work. I don't know what else to do. Please help. TQ

22. May 17, 2011

### Fenn

Hi sni,

Can you be more informative about what you are trying to do, and how it is not working?

23. May 17, 2011

### sni

i tried using \newln but the equation still exceeds the page.

24. May 17, 2011

### Fenn

Could you please post an example of what you are trying to do? These forums will parse LaTeX formatting if you enclose it within the a set of [ tex ] and [ /tex ] delimiters (remove the spaces to get them to work.)

eg:

$$\newcommand{\parenthnewln}[1]{\right.\\#1&\left.{}} \begin{split} f(x)=1+&g(x)\\ =1+&\left(x+x^2+\dots \parenthnewln{+}x^n+\ldots\right) \end{split}$$

You can also show your code verbatim by enclosing it in [ code ] and [ /code ] delimiters.

Code (Text):

\newcommand{\parenthnewln}[1]{\right.\\#1&\left.{}}

\begin{split}
f(x)=1+&g(x)\\
=1+&\left(x+x^2+\dots
\parenthnewln{+}x^n+\ldots\right)
\end{split}

25. May 17, 2011

### sni

[tex]
\begin{eqnarray}
\begin{split}
\frac{1}{2}v(e^{X}P_{1}+2e^{X}\frac{\partial P_{1}}{\partial X}+e^{X}\frac{\partial^2 P_{1}}{\partial X^2}-Ke^{-r(T-t)}\frac{\partial^2 P_{2}}{\partial X^2})+(r-\frac{1}{2}v)(e^{X}P_{1}+e^{X}\frac{\partial P_{1}}{\partial X}-Ke^{-r(T-t)}\frac{\partial P_{2}}{\partial X})
\\ + \rho\sigma v(e^{X}\frac{\partial P_{1}}{\partial v}+e^{X}\frac{\partial^2 P_{1}}{\partial X\partial v} -Ke^{-r(T-t)}\frac{\partial^2 P_{2}}{\partial X\partial v})+\frac{1}{2}v\sigma^2(e^{X}\frac{\partial^2 P_{1}}{\partial v^2}-Ke^{-r(T-t)}\frac{\partial^2 P_{2}}{\partial v^2}) +[\kappa(\theta-v)-\lambda v] \\ (e^{X}\frac{\partial P_{1}}{\partial v}-Ke^{-r(T-t)}\frac{\partial P_{2}}{\partial v})-r(e^{X}P_{1}-Ke^{-r(T-t)}P_{2})+(e^{X}\frac{\partial P_{1}}{\partial t}-rKe^{-r(T-t)}\partial P_{2}-Ke^{-r(T-t)}\frac{\partial P_{2}}{\partial t}) = 0
e^{X}\left[\frac{1}{2}v\frac{\partial^2 P_{1}}{\partial X^2}+\rho\sigma v\frac{\partial^2 P_{1}}{\partial X\partial v}+\frac{1}{2}v\sigma^2\frac{\partial^2 P_{1}}{\partial v^2} +[\kappa(\theta-v)-\lambda v]\frac{\partial P_{1}}{\partial v}+(r+\frac{1}{2}v)\frac{\partial P_{1}}{\partial X}+\frac{\partial P_{1}}{\partial t}\right] \\
- Ke^{-r(T-t)}\left[\frac{1}{2}v\frac{\partial^2 P_{2}}{\partial X^2}+\rho\sigma v\frac{\partial^2 P_{2}}{\partial X\partial v}+\frac{1}{2}v\sigma^2\frac{\partial^2 P_{2}}{\partial v^2}+[\kappa(\theta-v)-\lambda v]\frac{\partial P_{2}}{\partial v}+(r-\frac{1}{2}v)\frac{\partial P_{2}}{\partial X}+\frac{\partial P_{2}}{\partial t}\right] &=& 0
\end{split}
\end{eqnarray}
[\tex]

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook