Math & Sciencespecial layout for huge equations

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
tyltus
Posts: 12
Joined: Tue Nov 10, 2009 12:03 pm

special layout for huge equations

Post by tyltus »

Hi there


Is there a possibility to change the page layout for the align environment?

Normally formulas produced with align are centered, which looks quite good. But as soon as the formula get's longer than \textwidth, it is aligned with the lefthand side of the text instead.

Now for many formulas this might look good, but in my report I have to write several really huge formulas (Lagrangian method for 10DOF) which I can just barely fit within a page. But because some of the lines are a bit too wide and there are a few lines too much, the formula looks a bit crammed to the bottom-right of the page.

One way I found to get this formula to look better is to decrease the pagemargin, but this makes the rest of the document harder to read. I also tried to set the margins to rubber lengths, but I couldn't get this to work.
What I would prefere is to somehow tell the align environment to allways be centered on the middle of the text, so that when the content is too wide it just overextends on both sides. Is something like this possible?


Please excuse the poor command usage. I've worked with latex for a while but never had to change our template; and my lack of english vocabulary doesn't help neither.
I hope you can still understand my question and maybe even help me with it :)
Best regards
Martin

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
php1ic
Posts: 192
Joined: Wed Jan 28, 2009 8:17 pm

special layout for huge equations

Post by php1ic »

Try using the split environment which is part of amsmath. You have to manually specify where to break the line, but I think it will do what you want.

Code: Select all

\begin{equation}
\begin{split}
f(x) &= x^4 + x^5\\
     &\quad + x^3 + x^2 + x
\end{split}
\end{equation}
tyltus
Posts: 12
Joined: Tue Nov 10, 2009 12:03 pm

special layout for huge equations

Post by tyltus »

Hello

Unfortunately, this doesn't help me, since the split environment seams to be doing something similar to the align environment.

Here a little mini-example to visualize my point:

Code: Select all

\documentclass[a4paper]{report}
\pagestyle{plain}
\usepackage{amsmath}
\begin{document}
This is just some text which should show how wide the paragraph looks and it's going to be repeated now:
This is just some text which should show how wide the paragraph looks and it's going to be repeated now:
This is just some text which should show how wide the paragraph looks but it's no longer going to be repeated now.

\begin{align}
Long\ equation=&some\ numbers\ combined\ with\ some\ variables\ which\ take\ up\ a\ lot\ of\ space\nonumber\\
&+ one\ line\ is\ not\ enough\ to\ contain\ the\ whole\ equation\nonumber\\
&+ some\ lines\ might\ be\ quite\ long\ but\ would\ look\ stupid\ if\ you\ break\ them\ up.
\end{align}
\begin{align}
Short= short,\ centered\ equation\ for\ comparison
\end{align}
\end{document}
If you compile this example, you see that the equation is wider than the paragraph, but it's only overextending to the righthand side.
How can I make this equation beeing still centered in the middle like the normal equation?

Yes, I know this is not normally needed and it would be better to split up the long lines. But if I do this, the equation will vertically be too long for the page...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: special layout for huge equations

Post by localghost »

Build a concrete example with one of the concerned equations.


Best regards
Thorsten¹
tyltus
Posts: 12
Joined: Tue Nov 10, 2009 12:03 pm

special layout for huge equations

Post by tyltus »

Build a concrete example with one of the concerned equations.
As you wish! I hoped to avoid this, but here is the biggest culprit in question:

Code: Select all

\documentclass[a4paper]{report}
\pagestyle{plain}
\usepackage{amsmath}
\newcommand{\spsi}{\hspace{1pt}\mathrm{s}\delta\hspace{1pt}}
\newcommand{\cpsi}{\hspace{1pt}\mathrm{c}\delta\hspace{1pt}}
\newcommand{\salpha}[1]{\hspace{1pt}\mathrm{s}\alpha_#1\hspace{1pt}}
\newcommand{\ssalpha}[1]{\hspace{1pt}\mathrm{s}^2\alpha_#1\hspace{1pt}}
\newcommand{\calpha}[1]{\hspace{1pt}\mathrm{c}\alpha_#1\hspace{1pt}}
\newcommand{\csalpha}[1]{\hspace{1pt}\mathrm{c}^2\alpha_#1\hspace{1pt}}
\begin{document}
\begin{align}
L=&\frac{1}{2} m_v(\dot{x}^2+\dot{y}^2+\dot{z}^2)+2m_w(\dot{x}^2+\dot{y}^2+\overline{\dot{z}_{ij}^2})\qquad+2m_w\cdot\nonumber\\
&[\nonumber\\
&\quad2\dot{x}\{(\dot{z}-\overline{\dot{z}_{ij}})[\cpsi\gamma+\spsi\epsilon]+\nonumber\\
&\qquad\dot{\delta}[(-\spsi\gamma+\cpsi\epsilon)(z-\overline{z_{ij}})-\spsi(1+\frac{1}{2}\gamma^2)\overline{l_j}]+\nonumber\\
&\qquad\dot{\epsilon}[(\cpsi\epsilon\gamma+\spsi(1+\epsilon^2))(z-\overline{z_{ij}})]+\nonumber\\
&\qquad\dot{\gamma}\cpsi[(1+\frac{1}{2}\epsilon^2+\gamma^2)(z-\overline{z_{ij}})+\gamma \overline{l_j}]\}\nonumber\\
%
&+2\dot{y}\{(\dot{z}-\overline{\dot{z}_{ij}})[\spsi\gamma-\cpsi\epsilon]+\nonumber\\
&\qquad\dot{\delta}[(\cpsi\gamma+\spsi\epsilon)(z-\overline{z_{ij}})+\cpsi(1+\frac{1}{2}\gamma^2)\overline{l_j}]+\nonumber\\
&\qquad\dot{\epsilon}[(\spsi\epsilon\gamma-\cpsi(1+\epsilon^2))(z-\overline{z_{ij}})]+\nonumber\\
&\qquad\dot{\gamma}\spsi[(1+\frac{1}{2}\epsilon^2+\gamma^2)(z-\overline{z_{ij}})+\gamma \overline{l_j}]\}\nonumber\\
%
&+(\dot{z}^2-2\dot{z}\overline{\dot{z}_{ij}}+\overline{\dot{z}_{ij}^2})[\gamma^2+\epsilon^2]\nonumber\\
%
&+\dot{\delta}^2[(\gamma^2+\epsilon^2)(z^2-2z\overline{z_{ij}}+\overline{z_{ij}^2})+(1+\gamma^2)\overline{l_j^2}+(1+\epsilon^2)w^2+\nonumber\\
&\qquad2\gamma(z\overline{l_j}-\overline{z_{ij}l_j})+2\epsilon\overline{z_{ij}w_i}]\nonumber\\
%
&+\dot{\epsilon}^2[(1+2\epsilon^2)(z^2-2z\overline{z_{ij}}+\overline{z_{ij}^2})+(\epsilon^2+\gamma^2)w^2+2\epsilon\overline{z_{ij}w_i}]\nonumber\\
%
&+\dot{\gamma}^2[(1+\epsilon^2+2\gamma^2)(z^2-2z\overline{z_{ij}}+\overline{z_{ij}^2})+\gamma^2\overline{l_j^2}+\epsilon^2w^2+\nonumber\\
&\qquad 2\gamma(z\overline{l_j}-\overline{z_{ij}l_j})+2\epsilon\overline{z_{ij}w_i}] \nonumber\\
%
&+2\dot{\delta}[-\epsilon(\dot{z}\overline{l_j}-\overline{\dot{z}_{ij}l_ij})+\gamma\overline{\dot{z}_{ij}w_i}]
+2\dot{\epsilon}[\epsilon(\dot{z} z-\dot{z}\overline{z_{ij}}-\overline{\dot{z}_{ij}}z+\overline{\dot{z}_{ij}z_{ij}})+(\gamma^2+\epsilon^2)\overline{\dot{z}_{ij}w_i}] \nonumber\\
&+2\dot{\gamma}\gamma[(\dot{z} z-\dot{z}\overline{z_{ij}}-\overline{\dot{z}_{ij}}z+\overline{\dot{z}_{ij}z_{ij}}) +\gamma(\dot{z}\overline{l_j}-\overline{\dot{z}_{ij}l_j})+\epsilon\overline{\dot{z}_{ij} w_i}]\nonumber\\
%
&+2\dot{\delta}\dot{\epsilon}[-\gamma(z^2-2z\overline{z_{ij}}+\overline{z_{ij}^2})+
\gamma w^2-(1+\epsilon^2+\frac{1}{2}\gamma^2)(z\overline{l_j}-\overline{z_{ij}l_j})]\nonumber\\
%
&+2\dot{\delta}\dot{\gamma}[\epsilon(z^2-2z\overline{z_{ij}}+\overline{z_{ij}^2})+
\epsilon w^2+\epsilon\gamma(z\overline{l_j}-\overline{z_{ij}l_j})+(1+2\epsilon^2+\gamma^2)\overline{z_{ij}w_i}]\nonumber\\
%
&+2\dot{\epsilon}\dot{\gamma}\gamma[\epsilon(z^2-2z\overline{z_{ij}}+\overline{z_{ij}^2})+\epsilon w^2+\overline{z_{ij}w_i}]\nonumber\\
&]\nonumber\\
%
&+\frac{1}{2}(I_{vx}+I_{wr}(2+\csalpha{l}+\csalpha{r})+I_{wy}(\ssalpha{l}+\ssalpha{r}))
[\dot{\delta}^2\gamma^2+\dot{\epsilon}^2(1-\gamma^2)-2\dot{\delta}\dot{\epsilon}\gamma]\nonumber\\
&+\frac{1}{2}(I_{vy}+I_{wy}(2+\csalpha{l}+\csalpha{r})+I_{wr}(\ssalpha{l}+\ssalpha{r}))[\dot{\delta}^2\epsilon^2+\dot{\gamma}^2+2\dot{\delta}\dot{\gamma}\epsilon]\nonumber\\
&+\frac{1}{2}(I_{vz}+4I_{wr})[\dot{\delta}^2(1-\epsilon^2-\gamma^2)+\dot{\epsilon}^2\gamma^2+2\dot{\delta}\dot{\epsilon}\gamma]\nonumber\\
%
&+I_{vxz}[\dot{\delta}^2\gamma-\dot{\epsilon}^2\gamma-\dot{\delta}\dot{\epsilon}(1-\frac{1}{2}\epsilon^2-2\gamma^2)]
%
+\frac{1}{2} I_{wy}(\dot{\zeta}_{lf}^2+\dot{\zeta}_{rf}^2+\dot{\zeta}_{lb}^2+\dot{\zeta}_{rb}^2)\nonumber\\
%
&-I_{wy}[(\dot{\delta}\epsilon+\dot{\gamma})(\dot{\zeta}_{lf}\calpha{l}+\dot{\zeta}_{rf}\calpha{r}+\dot{\zeta}_{lb}+\dot{\zeta}_{rb})
+(\dot{\delta}\gamma-\dot{\epsilon}(1-\frac{1}{2}\gamma^2))(\dot{\zeta}_{lf}\salpha{l}+\dot{\zeta}_{rf}\salpha{r})]\nonumber\\
%
&+(I_{wy}-I_{wr})(\salpha{l}\calpha{l}+\salpha{r}\calpha{r}) [\dot{\delta}^2\epsilon\gamma-\dot{\epsilon}\dot{\gamma}(1-\frac{1}{2}\gamma^2)-\dot{\delta}\dot{\epsilon}\epsilon+\dot{\delta}\dot{\gamma}\gamma]\nonumber\\
%
&+I_{wr}[\frac{1}{2}(\dot{\alpha}_l^2+\dot{\alpha}_r^2)+(\dot{\delta}(1-\frac{1}{2}\epsilon^2-\frac{1}{2}\gamma^2)+\dot{\epsilon}\gamma)(\dot{\alpha}_l+\dot{\alpha}_r)]\nonumber\\
%
&-m_v\,g\,z-4m_w\,g\,\overline{z_{ij}}
\end{align}
\end{document}
No, don't even try to understand what the single terms are supposed to mean ;)
Just take it for granted that this is a valid formula that I wish to somehow place on a single page and that I would like to have it more to the center of the page without chaning the layout of the written text.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

special layout for huge equations

Post by localghost »

tyltus wrote:[...] No, don't even try to understand what the single terms are supposed to mean ;)
Just take it for granted that this is a valid formula that I wish to somehow place on a single page and that I would like to have it more to the center of the page without chaning the layout of the written text.
Beyond question. But as a physicist I have seen equations that are much more scary (e. g. Schroedinger equation in polar coordinates).

Use the flalign environment and slightly rearrange the lines of your equations.
tyltus
Posts: 12
Joined: Tue Nov 10, 2009 12:03 pm

special layout for huge equations

Post by tyltus »

localghost wrote:(e. g. Schroedinger equation in polar coordinates).
Uuuh, sounds sweet :)
localghost wrote:Use the flalign environment and slightly rearrange the lines of your equations.
Thanks for the hint with flalign, I didn't know about this environment before.
Unfortunately it still doesn't really do what I was hoping for! It seems that flalign just left-flushes the align environment which is usually centered. But my problem is not that the align environment is usually centered but rather that it's no longer centered once the equations are wider than \textwidth. So for the above equation the change from align to flalign didn't do anything at all.
Is there really no simple way to keep the align environment centered even if the lignes are wider than textwidth?

Once again sorry for my poor problem description!
If all else fails, I can just use flalign for all equations so there is no longer the discrepancy between the short centered equations and the long left-flushed ones.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

special layout for huge equations

Post by frabjous »

Have you tried either the multline or gathered environments from AMS math? See Voss's mathmode documentation, pages 49-52.
php1ic
Posts: 192
Joined: Wed Jan 28, 2009 8:17 pm

Re: special layout for huge equations

Post by php1ic »

I think you problem may be the difference between the margins and the entire page. Assuming your textwidth is centered on the page, if the line is longer than the textwidth, it is started at the left margin and runs over the right margin, no longer appearing to be centered on the page.

If you increase the textwidth and move the lefthand margin for the single page, it may help to get what you want.
tyltus
Posts: 12
Joined: Tue Nov 10, 2009 12:03 pm

special layout for huge equations

Post by tyltus »

php1ic wrote:I think you problem may be the difference between the margins and the entire page. Assuming your textwidth is centered on the page, if the line is longer than the textwidth, it is started at the left margin and runs over the right margin, no longer appearing to be centered on the page.

If you increase the textwidth and move the lefthand margin for the single page, it may help to get what you want.
Yes, this is exactly the problem!

So can I change those values for a single page only?
Would it even be possible to create a minipage which has a smaller left margin and a wider textwidth than the rest of the page?
If the answer to any of those questions is yes, then: how?
Post Reply