The discussion revolves around formatting equations in LaTeX, specifically how to split a long term in an equation so that the second half aligns directly under a specific operator (the '+' sign) rather than under the equality sign. Participants suggest using the "align*" and "split" environments for better control over the layout. The use of ampersands (&) as alignment points is emphasized, allowing for precise placement of terms across multiple lines. There are also discussions about nesting environments and managing spacing to achieve the desired appearance. Additionally, participants share resources, including guides on LaTeX formatting, and discuss how to number multiline equations effectively using the subequations environment. The conversation highlights the challenges of formatting complex equations and offers practical solutions for achieving clarity and organization in mathematical presentations.
#1
EngWiPy
1,361
61
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?
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?).
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*}<br />
f(x) = 1 & + a + bx + cx^2 \\<br />
& + dx^3 + ex^4<br />
\end{align*}
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
EngWiPy
1,361
61
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.
Thank you all for replying, but may be I did not make my point clear, so I will give an example:
\begin{equation}\begin{split}f(x)=&1+g(x)\\<br />
=&1+\text{Expansion of g(x)}<br />
\end{split}<br />
\end{equation}
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
Fenn
76
0
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:
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
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
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?
<br />
\begin{equation}<br />
\begin{split}<br />
f(x) = 1 +& g(x) \\<br />
=1 +& sin(x) + cos(x) + \cdots \\<br />
+&tan(x)<br />
\end{split}<br />
\end{equation}<br />
#10
EngWiPy
1,361
61
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
Fenn
76
0
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
EngWiPy
1,361
61
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.
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
Fenn
76
0
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:
We are learning something new each time. Thank you all guys.
#16
Fenn
76
0
One thing I'd like to learn is how to number multiline equations with subindices like (a) (b) (c).
Something like
<br />
\begin{align}<br />
I = \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}<br />
\end{align}<br />
<br />
\end{align}<br />
\begin{align}<br />
f &= ma\\<br />
E &= mc^2\\<br />
\pi &\text{ is exactly three!}<br />
\end{align}<br />
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
Fenn
76
0
Alright, I found my answer, in case anyone is looking. It's the subequations environment from the amsmath package.
<br />
\begin{align}<br />
I = \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}<br />
\end{align}<br />
<br />
\begin{subequations}\begin{align}<br />
f &= ma\\<br />
E &= mc^2\\<br />
\pi &\text{ is exactly three!}<br />
\end{align}\end{subequations}<br />
#18
EngWiPy
1,361
61
Fenn said:
Alright, I found my answer, in case anyone is looking. It's the subequations environment from the amsmath package.
<br />
\begin{align}<br />
I = \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}<br />
\end{align}<br />
<br />
\begin{subequations}\begin{align}<br />
f &= ma\\<br />
E &= mc^2\\<br />
\pi &\text{ is exactly three!}<br />
\end{align}\end{subequations}<br />
It is nice Fenn, thank you. I may re-consider the numbering of certain equations based on this.
Regards
#19
Fenn
76
0
I'm now using them for clusters of similar equations, so my index numbers don't get too outrageous.
Hi Fenn, I tried this but it didn't work. I don't know what else to do. Please help. TQ
#22
Fenn
76
0
Hi sni,
Can you be more informative about what you are trying to do, and how it is not working?
#23
sni
7
0
i tried using \newln but the equation still exceeds the page.
#24
Fenn
76
0
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.)
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:
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
sni
7
0
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
sni
7
0
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
sni
7
0
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
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:
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
Fenn
76
0
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
sni
7
0
yes,i 've figured that now. thanks though for your advise. i really2 appreciate it.