Multi-line Equation Problem in Latex

by S_David
Tags: equation, latex, multiline
 P: 587 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
 P: 175 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
P: 1,750
 Quote by S_David 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
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*}

Mentor
P: 14,243

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
 P: 587 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
 Sci Advisor P: 1,498 Once your inside the split environment you can simply use ampersands as alignment points. $$\begin{split} f(x) = 1 &+ \\ &g(x) \end{split}$$ $$\begin{split} f(x) = 1 &+ \\ &g(x) \end{split}$$
 P: 587 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
P: 74
 Quote by S_David 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.

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

\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}
 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{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}$$
 P: 587 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
 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.
P: 587
 Quote by 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.
Try this one Fenn:

$$\begin{split} f(x)=1+&g(x)\\ =1+&x+x^2+\dots\\ +&x^n \end{split}$$
Regards
 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.
 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{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}$$
 P: 587 We are learning something new each time. Thank you all guys.
 P: 74 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.
 P: 74 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}
P: 587
 Quote by 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}
It is nice Fenn, thank you. I may re-consider the numbering of certain equations based on this.

Regards

 Related Discussions Math & Science Software 1 Math & Science Software 2 Calculus & Beyond Homework 9 Precalculus Mathematics Homework 5 Precalculus Mathematics Homework 5