Register to reply

Multi-line Equation Problem in Latex

by S_David
Tags: equation, latex, multiline
Share this thread:
Fenn
#19
Jul21-09, 06:31 AM
P: 74
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]
minger
#20
Jul21-09, 08:04 AM
Sci Advisor
P: 1,498
[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!
sni
#21
May17-11, 06:10 AM
P: 7
Hi Fenn, I tried this but it didn't work. I don't know what else to do. Please help. TQ
Fenn
#22
May17-11, 07:18 AM
P: 74
Hi sni,

Can you be more informative about what you are trying to do, and how it is not working?
sni
#23
May17-11, 07:47 AM
P: 7
i tried using \newln but the equation still exceeds the page.
Fenn
#24
May17-11, 09:08 AM
P: 74
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.

\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}
sni
#25
May17-11, 09:15 AM
P: 7
[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]
Fenn
#26
May17-11, 10:05 AM
P: 74
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.

\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.
sni
#27
May17-11, 11:14 PM
P: 7
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
sni
#28
May17-11, 11:58 PM
P: 7
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
sni
#29
May18-11, 02:07 AM
P: 7
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

Quote Quote by Fenn View Post
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.

\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.
Fenn
#30
May20-11, 07:37 AM
P: 74
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.
sni
#31
May22-11, 09:05 AM
P: 7
yes,i 've figured that now. thanks though for your advise. i really2 appreciate it.


Register to reply

Related Discussions
Cut of text line in latex Math & Science Software 1
Multi-line Equation in Latex Math & Science Software 2
Find the equation of the normal line of the given parabola that is parallel to a line Calculus & Beyond Homework 9
Equation of line parallel to plane and intersaction with other line Precalculus Mathematics Homework 5
Equation of a line problem Precalculus Mathematics Homework 5