Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I try to write down the following equation:

\begin{equation}
\begin{flalign*}
\left \| \vec{r}_1 - \vec{r}_2 \right \| = \\ 
\sqrt{( r_{1,x}-r_{2,x} )^2 + ( r_{1,y} - r_{2,y} )^2 } = \\ 
\sqrt{( (x\cos(\Omega y)-y\sin(\Omega y))+\rho\cos(\Omega y) )^2 + ( x\sin(\Omega y)+y\cos(\Omega y) + \rho\sin(\Omega y) )^2 }
\end{flalign*}
\end{equation}

I am using the following math packages:

\usepackage{amsmath}
\usepackage{mathtools}

But instead to be write on the left side it's continuing to stay in the right side. How can I write it in a better way?

Thanks a lot!

share|improve this question
    
Is the fleqn option of article what you want? –  Raphael Feb 1 at 21:35
add comment

4 Answers

up vote 11 down vote accepted

First of all, flalign* starts math mode, so can not be nested inside equation.

Then, if you want the stuff inside flalign* to be left aligned, you have to put a & at the beginning of each line and a && at its end, like this:

\documentclass{article}
\usepackage{mathtools} % loads amsmath

\begin{document}
\begin{flalign*}
&\left \| \vec{r}_1 - \vec{r}_2 \right \| = &&\\
&\sqrt{( r_{1,x}-r_{2,x} )^2 + ( r_{1,y} - r_{2,y} )^2 } = &&\\
&\sqrt{( x\cos(\Omega y)-y\sin(\Omega y)+\rho\cos(\Omega y) )^2 + ( x\sin(\Omega y)+y\cos(\Omega y) + \rho\sin(\Omega y) )^2 }&&
\end{flalign*}
\end{document} 

enter image description here

The result is not really good, anyway. BTW, there was an unneeded right parenthesis after y\sin(\Omega y) and one before x\cos(\Omega y).

IMHO, you can also further eliminate parenthesis so to avoid bad boxes warnings, and move the equal sign down in the next line, in this way

\documentclass{article}
\usepackage{mathtools} % loads amsmath

\begin{document}
\begin{flalign*}
&\left \| \vec{r}_1 - \vec{r}_2 \right \| &&\\
&\quad=\sqrt{( r_{1,x}-r_{2,x} )^2 + ( r_{1,y} - r_{2,y} )^2 } &&\\
&\quad=\sqrt{( x\cos\Omega y-y\sin\Omega y+\rho\cos\Omega y )^2 + ( x\sin\Omega y+y\cos\Omega y + \rho\sin\Omega y )^2 }&&
\end{flalign*}
\end{document} 

enter image description here

For a better looking square root you can insert a \vphantom{r_1^2} in the latter \sqrt:

\documentclass{article}
\usepackage{mathtools} % loads amsmath

\begin{document}
\begin{flalign*}
&\left \| \vec{r}_1 - \vec{r}_2 \right \| &&\\
&\quad=\sqrt{( r_{1,x}-r_{2,x} )^2 + ( r_{1,y} - r_{2,y} )^2 } &&\\
&\quad=\sqrt{\vphantom{r_1^2}( x\cos\Omega y-y\sin\Omega y+\rho\cos\Omega y )^2 + ( x\sin\Omega y+y\cos\Omega y + \rho\sin\Omega y )^2 }&&
\end{flalign*}
\end{document} 

enter image description here

share|improve this answer
    
Maybe a \quad to start the third row? –  egreg Feb 1 at 16:39
1  
@egreg Right, no bad boxes. –  karlkoeller Feb 1 at 16:59
    
Another option might be using multlined environment inside the last square root. –  Manuel Feb 1 at 17:27
    
Since the mathtools package loads the amsmath package, it's not necessary to load the latter package explicitly. To normalize the size of the two long square root symbols, you could encase the former in a \smash{...}, or at least a \smash[b]{...}, instruction. –  Mico Feb 1 at 17:32
    
@Mico Thanks, just copied the code and didn't notice that both package were loaded. In regards of \smashing the former, I prefer the result with a \vphantom. –  karlkoeller Feb 1 at 18:14
show 2 more comments

Is this what you want?

\begin{align*}
&\left \| \vec{r}_1 - \vec{r}_2 \right \| = \\ 
&\sqrt{( r_{1,x}-r_{2,x} )^2 + ( r_{1,y} - r_{2,y} )^2 } = \\ 
&\sqrt{( (x\cos(\Omega y)-y\sin(\Omega y))+\rho\cos(\Omega y) )^2 + ( x\sin(\Omega y)+y\cos(\Omega y) + \rho\sin(\Omega y) )^2 } 
\end{align*}

enter image description here

share|improve this answer
add comment

Or this

enter image description here

\documentclass[]{article}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
%\begin{equation}
\begin{align*}
\left \| \vec{r}_1 - \vec{r}_2 \right \| 
&=  \sqrt{( r_{1,x}-r_{2,x} )^2 + ( r_{1,y} - r_{2,y} )^2 } \\
&=
\sqrt{( (x\cos(\Omega y)-y\sin(\Omega y))+\rho\cos(\Omega y) )^2 + ( x\sin(\Omega y)+y\cos(\Omega y) + \rho\sin(\Omega y) )^2 }
\end{align*}
%\end{equation}
\end{document}
share|improve this answer
    
The bad box is over 52pt... –  karlkoeller Feb 1 at 16:31
    
@karlkoeller -- Mmmm, leaned sth from your post. Thanks. –  Jesse Feb 1 at 17:06
    
Just a quick note, the bad box is removed if the left margin is reduced. This example uses the default setting of LaTeX. –  Jesse Feb 1 at 17:30
add comment

Here's another option. Taking karlkoeller's code.
I use multlined environment inside the second square root (\qquad is just to move it to the right, you can substitute it with whatever you want, even delete it, since multline already adds some space).

\begin{align*}
    \left\| \vec{r}_1 - \vec{r}_2 \right\| &= \sqrt{(r_{1,x} - r_{2,x})^2 + (r_{1,y} - r_{2,y})^2 } \\
    &= \sqrt{\begin{multlined}
        (x\cos\Omega y - y\sin\Omega y + \rho\cos\Omega y)^2 \\
        \qquad + (x\sin\Omega y + y\cos\Omega y + \rho\sin\Omega y)^2
    \end{multlined}}
\end{align*}

enter image description here

EDIT

Still another two options.

\begin{align*}
    \left\| \vec{r}_1 - \vec{r}_2 \right\| &= \sqrt{(r_{1,x} - r_{2,x})^2 + (r_{1,y} - r_{2,y})^2 } \\
    \MoveEqLeft = \sqrt{\vphantom{r_1^2} (x\cos\Omega y - y\sin\Omega y + \rho\cos\Omega y)^2 + (x\sin\Omega y + y\cos\Omega y + \rho\sin\Omega y)^2}
\end{align*}

\begin{multline*}
    \left\| \vec{r}_1 - \vec{r}_2 \right\| = \sqrt{(r_{1,x} - r_{2,x})^2 + (r_{1,y} - r_{2,y})^2 } \\
    = \sqrt{\vphantom{r_1^2} (x\cos\Omega y - y\sin\Omega y + \rho\cos\Omega y)^2 + (x\sin\Omega y + y\cos\Omega y + \rho\sin\Omega y)^2}
\end{multline*}

Both of them look similar to this:

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.