New Reply

Multi-line Equation Problem in Latex

 
Share Thread Thread Tools
Jul20-09, 11:13 PM   #18
 

Multi-line Equation Problem in Latex


Quote by Fenn View Post
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
Jul21-09, 06:31 AM   #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]
Jul21-09, 08:04 AM   #20
 
Recognitions:
Science Advisor Science Advisor
[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!
May17-11, 06:10 AM   #21
sni
 
Hi Fenn, I tried this but it didn't work. I don't know what else to do. Please help. TQ
May17-11, 07:18 AM   #22
 
Hi sni,

Can you be more informative about what you are trying to do, and how it is not working?
May17-11, 07:47 AM   #23
sni
 
i tried using \newln but the equation still exceeds the page.
May17-11, 09:08 AM   #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}
May17-11, 09:15 AM   #25
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]
May17-11, 10:05 AM   #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.
May17-11, 11:14 PM   #27
sni
 
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
May17-11, 11:58 PM   #28
sni
 
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
May18-11, 02:07 AM   #29
sni
 
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 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.

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


Similar Threads for: Multi-line Equation Problem in Latex
Thread Forum Replies
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