Multi-line Equation Problem in Latex


by S_David
Tags: equation, latex, multiline
S_David
S_David is offline
#1
Jul16-09, 09:20 AM
P: 590
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
Phys.Org News Partner Science news on Phys.org
Better thermal-imaging lens from waste sulfur
Hackathon team's GoogolPlex gives Siri extra powers
Bright points in Sun's atmosphere mark patterns deep in its interior
KLoux
KLoux is offline
#2
Jul16-09, 10:05 AM
P: 175
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
sylas
sylas is offline
#3
Jul16-09, 10:34 AM
Sci Advisor
sylas's Avatar
P: 1,750
Quote Quote by S_David View Post
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]

D H
D H is online now
#4
Jul16-09, 10:38 AM
Mentor
P: 14,434

Multi-line Equation Problem in Latex


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/amsmat...math-guide.pdf
amsmath user's guide: ftp://ftp.ams.org/pub/tex/doc/amsmath/amsldoc.pdf
S_David
S_David is offline
#5
Jul16-09, 11:02 AM
P: 590
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
minger
minger is offline
#6
Jul16-09, 02:34 PM
Sci Advisor
P: 1,498
Once your inside the split environment you can simply use ampersands as alignment points.
\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]
S_David
S_David is offline
#7
Jul16-09, 02:51 PM
P: 590
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
Fenn
Fenn is offline
#8
Jul16-09, 02:52 PM
P: 74
Quote Quote by S_David View Post
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
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:

\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
\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

\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]
minger
minger is offline
#9
Jul17-09, 07:50 AM
Sci Advisor
P: 1,498
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

\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]
S_David
S_David is offline
#10
Jul17-09, 09:23 AM
P: 590
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
Fenn
Fenn is offline
#11
Jul17-09, 10:21 AM
P: 74
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.
S_David
S_David is offline
#12
Jul17-09, 12:12 PM
P: 590
Quote Quote by Fenn View Post
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:

\begin{equation}
\begin{split}
f(x)=1+&g(x)\\
=1+&x+x^2+\dots\\
+&x^n
\end{split}
\end{equation}
Regards
minger
minger is offline
#13
Jul17-09, 12:46 PM
Sci Advisor
P: 1,498
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.
Fenn
Fenn is offline
#14
Jul17-09, 12:50 PM
P: 74
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:

\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]
S_David
S_David is offline
#15
Jul17-09, 03:22 PM
P: 590
We are learning something new each time. Thank you all guys.
Fenn
Fenn is offline
#16
Jul18-09, 08:45 AM
P: 74
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.
Fenn
Fenn is offline
#17
Jul20-09, 05:17 PM
P: 74
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]
S_David
S_David is offline
#18
Jul20-09, 11:13 PM
P: 590
Quote 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


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