Math & ScienceToo long equation

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
avp3000
Posts: 49
Joined: Thu Nov 15, 2007 4:22 pm

Too long equation

Post by avp3000 »

Hello everybody,

I have a very long equation and this causes me some problems. I want it to look the following way:

left side = right side\\
+continuation of right side\\
=right side again modified\\
+continuation of the modified right side\\
=result

I first used the align environment:

Code: Select all

\begin{align*}
\pi^{M}(s^{M},f^{M},x^{M}) :&= 12s^{M}+14f^{M}-(s^{M})^2-(x^{M}-4)^2-(f^{M})^2-x^{M}f^{M}-(x^{M})^2
                          &=12\times6+14\times\dfrac{48}{7}-6^2-\left(\dfrac{2}{7}-4\right)^2-\left(\dfrac{48}{7}\right)^2
                             -\dfrac{2}{7}\times\dfrac{48}{7}-\left(\dfrac{2}{7}\right)^2\\
                            &=69,14
\end{align*}
However, the problem is, that I'm doing this in a presentation and the column width is limited. Despite of that {align} doesn't adjust the expression to the margins of the slide (by braking the expression before a + or a - sign and continuing it on the next line), but makes it go out of the whole page area.

I thought of multline, however, the problem is, that multline aligns the first row left the second to last but one rows centered and last row right. This works well, if one has an expression of the type a+b=c+d+e+f+g+h=j, where there's only one row between initial row and result. However, in my case, I have some mathematical transformation (meaning an additional row) and so I need the equal sign of the row: "12\times6+14\times\dfrac{48}{7}-6^2-\left(\dfrac{2}{7}-4\right)^2-\left(\dfrac{48}{7}\right)^2
-\dfrac{2}{7}\times\dfrac{48}{7}-\left(\dfrac{2}{7}\right)^2" to be aligned under the first equal sign. So now I use this version:

Code: Select all

\begin{align*}
\pi^{M}(s^{M},f^{M},x^{M}) :=& 12s^{M}+14f^{M}-(s^{M})^2-(x^{M}-4)^2-(f^{M})^2\\
                             &-x^{M}f^{M}-(x^{M})^2\pause\\
                            =&12\times6+14\times\dfrac{48}{7}-6^2-\left(\dfrac{2}{7}-4\right)^2-\left(\dfrac{48}{7}\right)^2\\
                             &-\dfrac{2}{7}\times\dfrac{48}{7}-\left(\dfrac{2}{7}\right)^2\pause\\
                            =&69,14\pause
\end{align*}
Does anybody have better ideas? Thank you :)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Too long equation

Post by localghost »

You can try the split environment, which is also provided by the amsmath package. To get a proper alignment, there are some tricky things to do.

Code: Select all

\begin{align*}
  \pi^{M}(s^{M},f^{M},x^{M}): 
  \begin{split}
    &= 12s^{M}+14f^{M}-(s^{M})^2-(x^{M}-4)^2 \\
    &\quad -(f^{M})^2-x^{M}f^{M}-(x^{M})^2
  \end{split}\\
  \begin{split}
    &= 12\times 6+14\times\frac{48}{7}-6^2-\left(\frac{2}{7}-4\right)^2 \\
    &\quad -\left(\frac{48}{7}\right)^2-\frac{2}{7}\times\frac{48}{7}-\left(\frac{2}{7}\right)^2
  \end{split}\\
  &=69,14
\end{align*}
Note that the alignment as known from the align environment has to be put into the split environment. More hints about typesetting mathematical expressions are given in "Math mode".


Best regards
Thorsten
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Too long equation

Post by Juanjo »

Here you have a different approach through the aligned environment:

Code: Select all

\newcommand{\coloneqq}{\mathrel{\mathop:}=} 
\begin{align*}
  \pi^{M}(s^{M},f^{M},x^{M})\coloneqq{}&
  \!\begin{aligned}[t] 
    &12s^{M}+14f^{M}-(s^{M})^2-(x^{M}-4)^2 \\
    &-(f^{M})^2-x^{M}f^{M}-(x^{M})^2
  \end{aligned}\\
  ={}&
  \!\begin{aligned}[t]
    &12\times 6+14\times\frac{48}{7}-6^2-\left(\frac{2}{7}-4\right)^2 \\
    &-\left(\frac{48}{7}\right)^2-\frac{2}{7}\times\frac{48}{7}
    -\left(\frac{2}{7}\right)^2
  \end{aligned}\\
  ={}&69,14
\end{align*}
The \! command removes a small space before the contents of the aligned environment. Note, in addition, the use of \coloneqq instead of :=. You can also get this character from txfonts. Finally, comparing with your second code, remark the braces after =, needed to get a proper spacing.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10343
Joined: Mon Mar 10, 2008 9:44 pm

Too long equation

Post by Stefan Kottwitz »

Hi,

we discussed a very similar issue today on Matheplanet.

Btw. I would try to use & at the equal sign. If you consider the mathematical style of multiline equations, perhaps have a look at for instance IEEE Computer Society Style Guide - Mathematical Expressions: If line breaks are needed in equations that appear in a paragraph, they should come after a plus sign, equals sign, or similar character. But of course there may be different styles.

Stefan
LaTeX.org admin
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Too long equation

Post by Juanjo »

Stefan_K wrote:Hi,

we discussed a very similar issue today on Matheplanet.

Btw. I would try to use & at the equal sign. If you consider the mathematical style of multiline equations, perhaps have a look at for instance IEEE Computer Society Style Guide - Mathematical Expressions: If line breaks are needed in equations that appear in a paragraph, they should come after a plus sign, equals sign, or similar character. But of course there may be different styles.

Stefan
Concerning the discussion in MathPlanet, I can't follow it, since I don't understand German. Anyway, please note that the quoted advice given in the IEEE guide applies to inline formulas (i.e. formulas inside paragraphs). However, in displayed formulas, the line break comes before binary relations or operators. So, in the code you posted in MathPlanet, I would suggest to move the + signs to the beginning of the next line (they are not properly spaced indeed).
I apologize if I shouldn't refer here to topics in a different forum.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10343
Joined: Mon Mar 10, 2008 9:44 pm

Re: Too long equation

Post by Stefan Kottwitz »

Hi Juanjo,

I just mentioned the topic of the other forum because of the coincidence of similar code, aligned inside align. Just wanted to point at the code, not at the discussion in german.
I remembered the line break after plus/minus etc. and just gave the link to that style guide quickly, I did not reed further. Now I read the part on displayed equations too. If you know more ressources concerning mathematical style I would be glad to know.

Stefan
LaTeX.org admin
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Too long equation

Post by Juanjo »

Hi Stefan,
Stefan_K wrote: If you know more ressources concerning mathematical style I would be glad to know.
The primary resource I know is the following book:

Ellen Swanson: Mathematics into Type. Updated by Arlene O'Sean and Antoinette Schleyer. American Mathematical Society, 1999.

It is cited in every author's guide for the publications of the AMS. There are similar books, like that of N. J. Higham cited in the IEEE page you linked, or Handbook of Typography for the Mathematical Sciences, by Steven G. Krantz, published by Chapman& Hall. Since I have access to these books, I have not needed to search for online resources. I've found anyway an interesting page here. Surely, a careful search would yield more suitable links.

By the way, congratulations for your TeXblog, that up to today I hadn't had got time to visit in detail.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Post Reply