Multi-line Equation Problem in Latex

  • LaTeX
  • Thread starter EngWiPy
  • Start date
  • Tags
    Latex
In summary: I think it should work.\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}In summary, the conversation discusses how to properly format equations with long terms and split them into multiple lines while keeping them aligned. Different methods are suggested, including using the align and split environments, as well as specific commands such as \newln and \parenthnew
  • #1
EngWiPy
1,368
61
Hello,

I have an equation like this one:

[tex]f(x)=1+g(x)[/tex]

where [tex]g(x)[/tex] 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
 
Physics news on Phys.org
  • #2
I think there is some information on this in "The Not So Short Guide to [tex]\LaTeXe[/tex]." 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 [tex]\LaTeXe[/tex]." It's available here: http://tobi.oetiker.ch/lshort/lshort.pdf
 
Last edited:
  • #3
S_David said:
Hello,

I have an equation like this one:

[tex]f(x)=1+g(x)[/tex]

where [tex]g(x)[/tex] 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

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:
[tex]\begin{align*}
f(x) = 1 & + a + bx + cx^2 \\
& + dx^3 + ex^4
\end{align*}[/tex]​
 
Last edited:
  • #4
Even better, use the AMSLaTex macros, which are part of the standard LaTeX distribution.

A Short Math Guide for LaTeX: ftp://ftp.ams.org/pub/tex/doc/amsmath/short-math-guide.pdf
amsmath user's guide: ftp://ftp.ams.org/pub/tex/doc/amsmath/amsldoc.pdf
 
  • #5
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 environment becomes above and under the '+' sign, and not in the same line. This is exactly my problem.

Regards
 
  • #6
Once your inside the split environment you can simply use ampersands as alignment points.
Code:
\begin{equation}
\begin{split}
f(x) = 1 &+ \\
 &g(x)
\end{split}
\end{equation}
[tex]
\begin{equation}
\begin{split}
f(x) = 1 &+ \\
&g(x)
\end{split}
\end{equation}
[/tex]
 
  • #7
Thank you all for replying, but may be I did not make my point clear, so I will give an example:

[tex]\begin{equation}\begin{split}f(x)=&1+g(x)\\
=&1+\text{Expansion of g(x)}
\end{split}
\end{equation}[/tex]

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
S_David said:
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 environment becomes above and under the '+' sign, and not in the same line. This is exactly my problem.

Regards

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:
\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:
\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:
\newcommand{\parenthnewln}{\right.\\&\left.\quad\quad{}}

Again, the spacing can be adjusted.

[tex]
\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}
[/tex]

To fit your example:

[tex]
\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}
[/tex]
 
  • #9
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:
\begin{equation}
\begin{split}
f(x) &= 1 +& g(x) \\
 &=1 +& sin(x) + cos(x) + \cdots \\
 & +&tan(x)
\end{split}
\end{equation}
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?
[tex]
\begin{equation}
\begin{split}
f(x) = 1 +& g(x) \\
=1 +& sin(x) + cos(x) + \cdots \\
+&tan(x)
\end{split}
\end{equation}
[/tex]
 
  • #10
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
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
Fenn said:
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.

Try this one Fenn:

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

Regards
 
  • #13
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
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:
\newcommand{\parenthnewln}[1]{\right.\\#1&\left.{}}
\begin{equation}
\begin{split}
f(x)=1+&g(x)\\
=1+&\left(x+x^2+\dots
\parenthnewln{+}x^n+\ldots\right)
\end{split}
\end{equation}

[tex]
\newcommand{\parenthnewln}[1]{\right.\\#1&\left.{}}
\begin{equation}
\begin{split}
f(x)=1+&g(x)\\
=1+&\left(x+x^2+\dots
\parenthnewln{+}x^n+\ldots\right)
\end{split}
\end{equation}
[/tex]
 
  • #15
We are learning something new each time. Thank you all guys.
 
  • #16
One thing I'd like to learn is how to number multiline equations with subindices like (a) (b) (c).

Something like

[tex]
\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}
[/tex]

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
Alright, I found my answer, in case anyone is looking. It's the subequations environment from the amsmath package.

[tex]
\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}
[/tex]
 
  • #18
Fenn said:
Alright, I found my answer, in case anyone is looking. It's the subequations environment from the amsmath package.

[tex]
\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}
[/tex]

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

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

[tex]
\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}
[/tex]
 
  • #20
[tex]
\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}
[/tex]

Nice! big fan!
 
  • #21
Hi Fenn, I tried this but it didn't work. I don't know what else to do. Please help. TQ
 
  • #22
Hi sni,

Can you be more informative about what you are trying to do, and how it is not working?
 
  • #23
i tried using \newln but the equation still exceeds the page.
 
  • #24
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:

[tex]

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

[/tex]

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

Code:
\newcommand{\parenthnewln}[1]{\right.\\#1&\left.{}}
\begin{equation}
\begin{split}
f(x)=1+&g(x)\\
=1+&\left(x+x^2+\dots
\parenthnewln{+}x^n+\ldots\right)
\end{split}
\end{equation}
 
  • #25
[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]
 
  • #26
Here's a quick tweaking of your markup, where I have used a modified version of these \newln and \parenthnewln commands that I suggested in an earlier post:

[tex]

\newcommand{\newln}{\\&\hspace{2em}}
\newcommand{\parenthnewln}{\right.\newln\left.{}}

\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})&\newln
%
+(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})&\newln
%
+\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})\newln
%
+\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})&\newln
%
+[\kappa(\theta-v)-\lambda v] (e^{X}\frac{\partial P_{1}}{\partial v}-Ke^{-r(T-t)}\frac{\partial P_{2}}{\partial v})&\newln
%
-r(e^{X}P_{1}-Ke^{-r(T-t)}P_{2})\newln
%
+(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}\parenthnewln
%
+[\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]\newln
%
-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}\parenthnewln
%
+\frac{1}{2}v\sigma^2\frac{\partial^2 P_{2}}{\partial v^2}\parenthnewln
%
+[\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]

For some reason the [ tex ] markup does not appear to be working properly, so I have included the code as well.

Code:
\newcommand{\newln}{\\&\hspace{2em}}
\newcommand{\parenthnewln}{\right.\newln\left.{}}

\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})&\newln
%
+(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})&\newln
%
+\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})\newln
%
+\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})&\newln
%
+[\kappa(\theta-v)-\lambda v] (e^{X}\frac{\partial P_{1}}{\partial v}-Ke^{-r(T-t)}\frac{\partial P_{2}}{\partial v})&\newln
%
-r(e^{X}P_{1}-Ke^{-r(T-t)}P_{2})\newln
%
+(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}\parenthnewln
%
+[\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]\newln
%
-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}\parenthnewln
%
+\frac{1}{2}v\sigma^2\frac{\partial^2 P_{2}}{\partial v^2}\parenthnewln
%
+[\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}

I have put new lines within an equation using the \newln command. If the new line is within a set of parenthesis (the \left[ and \right]), then I use \parenthnewln.

Remember that you can always add white space (blank lines need the % comment in equation environments) to make your work more legible.
 
  • #27
thank you so much! this looks so nice. does it only work to one single equation? can it be used for multiple equations e.g proof?thanks
 
  • #28
Fenn, I labeled the code \end{split}\label{eq:eu}\end{eqnarray} but the equation number disappears. I want it to be on the second formula.why is this so? the referencing works fine as the equation number shows
 
  • #29
Hi Fenn, I have tried on other LONG equations that I have. Unfortunately, not all worked out fine. Some were indented to half of the page and gone missing for the second half. I realize that this happens with multi equations where for example

\begin{eqnarray}
Eq 1 (Long) = Eq 2 (Long)
Eq 3 (Long) = Eq 4 (Long)
\end{eqnarray}

Hope you can help me with this problem. I have tons of equations to adjust. TQ so much

Fenn said:
Here's a quick tweaking of your markup, where I have used a modified version of these \newln and \parenthnewln commands that I suggested in an earlier post:

[tex]

\newcommand{\newln}{\\&\hspace{2em}}
\newcommand{\parenthnewln}{\right.\newln\left.{}}

\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})&\newln
%
+(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})&\newln
%
+\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})\newln
%
+\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})&\newln
%
+[\kappa(\theta-v)-\lambda v] (e^{X}\frac{\partial P_{1}}{\partial v}-Ke^{-r(T-t)}\frac{\partial P_{2}}{\partial v})&\newln
%
-r(e^{X}P_{1}-Ke^{-r(T-t)}P_{2})\newln
%
+(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}\parenthnewln
%
+[\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]\newln
%
-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}\parenthnewln
%
+\frac{1}{2}v\sigma^2\frac{\partial^2 P_{2}}{\partial v^2}\parenthnewln
%
+[\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]

For some reason the [ tex ] markup does not appear to be working properly, so I have included the code as well.

Code:
\newcommand{\newln}{\\&\hspace{2em}}
\newcommand{\parenthnewln}{\right.\newln\left.{}}

\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})&\newln
%
+(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})&\newln
%
+\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})\newln
%
+\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})&\newln
%
+[\kappa(\theta-v)-\lambda v] (e^{X}\frac{\partial P_{1}}{\partial v}-Ke^{-r(T-t)}\frac{\partial P_{2}}{\partial v})&\newln
%
-r(e^{X}P_{1}-Ke^{-r(T-t)}P_{2})\newln
%
+(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}\parenthnewln
%
+[\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]\newln
%
-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}\parenthnewln
%
+\frac{1}{2}v\sigma^2\frac{\partial^2 P_{2}}{\partial v^2}\parenthnewln
%
+[\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}

I have put new lines within an equation using the \newln command. If the new line is within a set of parenthesis (the \left[ and \right]), then I use \parenthnewln.

Remember that you can always add white space (blank lines need the % comment in equation environments) to make your work more legible.
 
  • #30
Hi sni,

Working with equation formatting and layout in LaTeX can get very tedious if the equation is very long. I suggest you start with smaller equations and practice using the markup to do what you want.

A very useful technique is to comment (%) out sections of equations while you're setting it up, and slowly removing the comment markers as you build it. When I posted my suggestion to your problem, I commented out all but the first line, checked to see what it looked like, and slowly introduced more of the equation as I became more familiar with its content, and the overall formatting use.
 
  • #31
yes,i 've figured that now. thanks though for your advise. i really2 appreciate it.
 

FAQ: Multi-line Equation Problem in Latex

What is a multi-line equation in Latex?

A multi-line equation in Latex is a mathematical equation that is written using the Latex typesetting language and is spread out over multiple lines. This is often used for longer and more complex equations that cannot fit on a single line.

How do I create a multi-line equation in Latex?

To create a multi-line equation in Latex, you can use the "align" environment. This environment allows you to align equations using the "&" symbol and break them into multiple lines using the "\\" command. You can also use the "split" environment to break a single equation into multiple lines.

How do I number multi-line equations in Latex?

To number multi-line equations in Latex, you can use the "align" environment with the "equation" option. This will automatically number each line of the equation. You can also use the "\notag" command to exclude specific lines from being numbered.

Can I add text or symbols in between lines of a multi-line equation in Latex?

Yes, you can add text or symbols in between lines of a multi-line equation in Latex. You can use the "\intertext" command to add text in between lines, and the "\quad" command to add spacing between symbols.

How do I align multiple multi-line equations in Latex?

To align multiple multi-line equations in Latex, you can use the "align" environment with the "&" symbol to align the equations at a specific point. You can also use the "alignat" environment to align equations at multiple points.

Similar threads

Replies
5
Views
2K
Replies
1
Views
1K
Replies
8
Views
2K
Replies
6
Views
2K
Replies
11
Views
6K
Replies
10
Views
2K
Back
Top