Math & ScienceLayout of a long equation

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
sml23
Posts: 2
Joined: Wed Jan 19, 2011 8:05 pm

Layout of a long equation

Post by sml23 »

Hi,

I have a bit of an issue with the layout of a long equation. I have a long formula, that I want to have across two lines, with the second line justified to the right of the page (kind of like a multline environment style), and then the result on a new line, aligned to the equals sign of the top line. I have managed a bodge with \quads, but I was hoping there would be a more elegant solution?

The closest I have come are this, using align and aligned:

Code: Select all

\documentclass[a4paper]{report}
\usepackage{fullpage}
\usepackage{hyperref}
\usepackage{amsmath}

\newcommand{\parr}[1]{\vec{#1_{||}}} 

\begin{document}

\begin{align}\left(1+\frac{|\parr{q}|^2}{|\parr{R}|^2}+\frac{2|\parr{q}|}{|\parr{R}|}\cos(\Phi_R-\phi)\right)^\frac{l}{2} &=\notag
\!\begin{aligned}[t]1-\frac{l}{2}\frac{|\parr{q}|^2}{|\parr{R}|^2}-l\frac{|\parr{q}|}{|\parr{R}|}\cos(\Phi_R-\phi)
+\frac{(l^2+2l)}{8}\Bigg[\frac{|\parr{q}|^4}{|\parr{R}|^4}\\
+4\frac{|\parr{q}|^2}{|\parr{R}|^2}\cos^2(\Phi_R-\phi)+4\frac{|\parr{q}|^3}{|\parr{R}|^3}\cos(\Phi_R-\phi)\Bigg]\\
\end{aligned}\\
&=1-\frac{l}{2}\frac{|\parr{q}|^2}{|\parr{R}|^2}-l\frac{|\parr{q}|}{|\parr{R}|}\cos(\Phi_R-\phi)+\frac{(l^2+2l)}{2}\frac{|\parr{q}|^2}{|\parr{R}|^2}\cos^2(\Phi_R-\phi)
\end{align}

\end{document}
and this, using flalign:

Code: Select all

\documentclass[a4paper]{report}
\usepackage{fullpage}
\usepackage{hyperref}
\usepackage{amsmath}

\newcommand{\parr}[1]{\vec{#1_{||}}} 

\begin{document}

\begin{flalign}
\left(1+\frac{|\parr{q}|^2}{|\parr{R}|^2}+\frac{2|\parr{q}|}{|\parr{R}|}\cos(\Phi_R-\phi)\right)^\frac{l}{2} =&&{}1-\frac{l}{2}\frac{|\parr{q}|^2}{|\parr{R}|^2}-l\frac{|\parr{q}|}{|\parr{R}|}\cos(\Phi_R-\phi)
+\frac{(l^2+2l)}{8}\Bigg[\frac{|\parr{q}|^4}{|\parr{R}|^4}  \notag\\
&&+4\frac{|\parr{q}|^2}{|\parr{R}|^2}\cos^2(\Phi_R-\phi)+4\frac{|\parr{q}|^3}{|\parr{R}|^3}\cos(\Phi_R-\phi)\Bigg]&\notag\\
=&&1-\frac{l}{2}\frac{|\parr{q}|^2}{|\parr{R}|^2}-l\frac{|\parr{q}|}{|\parr{R}|}\cos(\Phi_R-\phi)+\frac{(l^2+2l)}{2}\frac{|\parr{q}|^2}{|\parr{R}|^2}\cos^2(\Phi_R-\phi) &
\end{flalign}

\end{document}
What I really want is the first line from the first example, and the second and third lines from the second example. Is there a neat way to do this?

Thanks!

Sophia
Last edited by sml23 on Wed Jan 26, 2011 4:06 pm, edited 1 time in total.

Recommended reading 2024:

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

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

Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Layout of a long equation

Post by Juanjo »

In my opinion, none of both options, even improved, are acceptable, since you've chosen a bad break point. If a line is broken inside a bracketed expression, the second line should start at the right of the opening bracket. This is not correct:

Code: Select all

left = right 1 - [ right 2 
         + right 3 + right 4 ]
The above scheme is confusing, since the reader, at first sight, may think that right 3 sums to right 1.
This is correct:

Code: Select all

left = right 1 - [ right 2 
                     + right 3 + right 4 ]
More acceptable options:

Code: Select all

left = right 1 
         - [ right 2 + right 3 + right 4 ]
or even, using a third line:

Code: Select all

left = right 1 
         - [ right 2 
               + right 3 + right 4 ]
Following these ideas, I give some options for your equation:

Code: Select all

\documentclass[a4paper]{report}
\usepackage[margin=1.5cm]{geometry}
%\usepackage{amsmath}
\usepackage{mathtools}

\newcommand{\parr}[1]{\vec{#1_{\parallel}}} 
\newcommand{\qR}[1][1]{\ifnum#1=1 \frac{|\parr{q}|}{|\parr{R}|} \else
   \frac{|\parr{q}|^{#1}}{|\parr{R}|^{#1}} \fi}
\newcommand{\cPp}[1][1]{\ifnum#1=1 \cos(\Phi_R-\phi) \else \cos^{#1}(\Phi_R-\phi)\fi}

\newcommand{\tab}{\qquad}

\begin{document}

Writing $Q=|\parr{q}|\,/\,|\parr{R}|$ and $\gamma=\cPp$, we have
\begin{equation}
   \left(1+Q^2+2Q\gamma\right)^{1/2}=1-\frac{l}{2}Q^2-lQ\gamma
        +\frac{(l^2+2l)}{8}[ Q^4+4Q^2\gamma^2+4Q^3\gamma ] \\
   =1-\frac{l}{2}Q^2-lQ\gamma+\frac{(l^2+2l)}{2}Q^2\gamma^2,
\end{equation}

Let $Q=|\parr{q}|\,/\,|\parr{R}|$ and $\gamma=\cPp$. Then,
\begin{multline}
   \left(1+Q^2+2Q\gamma\right)^{1/2}=1-\frac{l}{2}Q^2-lQ\gamma
        +\frac{(l^2+2l)}{8}[ Q^4+4Q^2\gamma^2+4Q^3\gamma ] \\
   =1-\frac{l}{2}Q^2-lQ\gamma+\frac{(l^2+2l)}{2}Q^2\gamma^2,
\end{multline}

\begin{equation}
   \begin{split}
   \left(1+Q^2+2Q\gamma\right)^{1/2}&=1-\frac{l}{2}Q^2-lQ\gamma
        +\frac{(l^2+2l)}{8}[ Q^4+4Q^2\gamma^2+4Q^3\gamma ] \\
   &=1-\frac{l}{2}Q^2-lQ\gamma+\frac{(l^2+2l)}{2}Q^2\gamma^2,
   \end{split}
\end{equation}
where
\[ Q=\qR \qquad \text{and} \qquad \gamma=\cPp. \]

\begin{align}
   &\left(1+\qR[2]+2\qR\cPp\right)^{1/2} \notag \\
   &\tab=1-\frac{l}{2}\qR[2]-l\qR\cPp
        +\frac{(l^2+2l)}{8}\Bigg[ \qR[4]+4\qR[2]\cPp[2]+4\qR[3]\cPp \Bigg] \\
   &\tab=1-\frac{l}{2}\qR[2]-l\qR\cPp+\frac{(l^2+2l)}{2}\qR[2]\cPp[2] \notag
\end{align}

\begin{align}
   \MoveEqLeft\left(1+\qR[2]+2\qR\cPp\right)^{1/2} \notag \\
   &=1-\frac{l}{2}\qR[2]-l\qR\cPp
        +\frac{(l^2+2l)}{8}\Bigg[ \qR[4]+4\qR[2]\cPp[2]+4\qR[3]\cPp \Bigg] \\
   &=1-\frac{l}{2}\qR[2]-l\qR\cPp+\frac{(l^2+2l)}{2}\qR[2]\cPp[2] \notag
\end{align}

\begin{equation}
   \begin{split}
      &\left(1+\qR[2]+2\qR\cPp\right)^{1/2} \\
      &\tab =1-\frac{l}{2}\qR[2]-l\qR\cPp
         +\frac{(l^2+2l)}{8}\Bigg[ \qR[4]+4\qR[2]\cPp[2]+4\qR[3]\cPp \Bigg] \\
      &\tab=1-\frac{l}{2}\qR[2]-l\qR\cPp+\frac{(l^2+2l)}{2}\qR[2]\cPp[2]
   \end{split}
\end{equation}

\begin{equation}
   \begin{split}
      \MoveEqLeft\left(1+\qR[2]+2\qR\cPp\right)^{1/2} \\
      & =1-\frac{l}{2}\qR[2]-l\qR\cPp
         +\frac{(l^2+2l)}{8}\Bigg[ \qR[4]+4\qR[2]\cPp[2]+4\qR[3]\cPp \Bigg] \\
      & =1-\frac{l}{2}\qR[2]-l\qR\cPp+\frac{(l^2+2l)}{2}\qR[2]\cPp[2]
   \end{split}
\end{equation}

\begin{equation}
   \begin{split}
      \left(1+\qR[2]+2\qR\cPp\right)^{1/2}
      ={}& 1-\frac{l}{2}\qR[2]-l\qR\cPp \\
      &\tab+\frac{(l^2+2l)}{8}
           \Bigg[ \qR[4]+4\qR[2]\cPp[2]+4\qR[3]\cPp \Bigg] \\
      ={}& 1-\frac{l}{2}\qR[2]-l\qR\cPp+\frac{(l^2+2l)}{2}\qR[2]\cPp[2]
   \end{split}
\end{equation}

\begin{equation}
   \begin{split}
      &\left(1+\qR[2]+2\qR\cPp\right)^{1/2} \\
      &\tab =1-\frac{l}{2}\qR[2]-l\qR\cPp \\
      &\tab\phantom{{}={}}\tab+\frac{(l^2+2l)}{8}
       \Bigg[ \qR[4]+4\qR[2]\cPp[2]+4\qR[3]\cPp \Bigg] \\
      &\tab=1-\frac{l}{2}\qR[2]-l\qR\cPp+\frac{(l^2+2l)}{2}\qR[2]\cPp[2]
   \end{split}
\end{equation}

\begin{equation}
   \begin{split}
      &\left(1+\qR[2]+2\qR\cPp\right)^{1/2} \\
      &\tab =\!
       \begin{aligned}[t]
          &1-\frac{l}{2}\qR[2]-l\qR\cPp \\
          &\tab+\frac{(l^2+2l)}{8}
           \Bigg[ \qR[4]+4\qR[2]\cPp[2]+4\qR[3]\cPp \Bigg]
       \end{aligned} \\
      &\tab=1-\frac{l}{2}\qR[2]-l\qR\cPp+\frac{(l^2+2l)}{2}\qR[2]\cPp[2]
   \end{split}
\end{equation}

\end{document}
To simplify the input, I've defined the commands \qR and \cPp. Check the definition of \parr, slightly different from yours. See also the exponent 1/2. The mathtools package extends amsmath. If you don't use \MoveEqLeft (see the code), then you can safely load only amsmath. Anyway, read the manual of mathtools, since this package offers many interesting things. There is no unique way to achieve a particular arrangement, as you can easily realize. I hope this helps.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
sml23
Posts: 2
Joined: Wed Jan 19, 2011 8:05 pm

Re: Layout of a long equation

Post by sml23 »

Thanks for your help! I hadn't thought of the problem with starting a new line to the left of the bracket, but you're right, having the new line start within the bracket is much more readable. Cheers for pointing me in the direction of mathtools, some of the stuff in there looks really useful!

Thanks,

Sophia
Post Reply