# How to modify eqnarray?

I'm currently writing a maths undergrad dissertation using Texmaker, and when I use eqnarray. It keeps justifying all of the equations to the right but still in the center?

How do I change this so that they align on the left (but still in the center)? I.e. so all the equals signs align? For example:

\documentclass[11pt]{article}
\usepackage{amsmath}

\begin{document}
\begin{eqnarray}
\dfrac{d }{dx} \dfrac{y'}{\sqrt{1+(y')^2}} = 0\\
\Rightarrow \dfrac{d }{dx} \dfrac{f'(x)}{\sqrt{1+(f'(x))^2}}=0\\
\Rightarrow \displaystyle\int_b^a \dfrac{d }{dx} \dfrac{f'(x)}{\sqrt{1+(f'(x))^2}} \,dx= constant = C\\
\Rightarrow f'(x) = \dfrac{C}{\sqrt{1-C^2}} = m\\
\Rightarrow \quad f(x) = mx+ \text{constant}
\end{eqnarray}
\end{document}

-
Avoid eqnarray! Use the corresponding environments from »amsmath«. – Thorsten Donig Mar 1 '14 at 9:22
Thank you so so much for helping me everyone!! Think I've got the hang of it now :-) ! – Sarah Jayne Mar 1 '14 at 9:53
To be honest, I don't think you have accepted the best answer. (I clearly prefer Thorsten's or my own answer.) – Svend Tveskæg Mar 2 '14 at 6:13

The eqnarray environment is intended to a "left-center-right" aligned array of equations. You must mark the alignments with & signs (change every = to &=& ):

\dfrac{d }{dx} \dfrac{y'}{\sqrt{1+(y')^2}} &=& 0\\
\Rightarrow \dfrac{d }{dx} \dfrac{f'(x)}{\sqrt{1+(f'(x))^2}}&=&0\\
\Rightarrow \displaystyle\int_b^a \dfrac{d }{dx} \dfrac{f'(x)}{\sqrt{1+(f'(x))^2}} \,dx= constant &=& C\\
\Rightarrow f'(x) = \dfrac{C}{\sqrt{1-C^2}} &=& m\\
\Rightarrow \quad f(x) &=& mx+ \text{constant}
\end{eqnarray}


But eqnarray is not a good solution for arrays of equations, because spacing between the equation terms is inconsistent with spacing in other mathematical expressions. Use the amsmath package and align environment (here, only one &is needed in every equation):

\begin{align}
\dfrac{d }{dx} \dfrac{y'}{\sqrt{1+(y')^2}} &= 0\\
\Rightarrow \dfrac{d }{dx} \dfrac{f'(x)}{\sqrt{1+(f'(x))^2}}&=0\\
\Rightarrow \displaystyle\int_b^a \dfrac{d }{dx} \dfrac{f'(x)}{\sqrt{1+(f'(x))^2}} \,dx= constant &= C\\
\Rightarrow f'(x) = \dfrac{C}{\sqrt{1-C^2}} &= m\\
\Rightarrow \quad f(x) &= mx+ \text{constant}
\end{align}

-
Please give full MWEs instead of code snippers as answers. – Svend Tveskæg Mar 1 '14 at 9:49

The alignat environment from »amsmath« makes alignment easier. And »physics« simplifies the typesetting of derivatives.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{physics}

\begin{document}
\begin{alignat}{2}
&& \dv{x}\,\frac{y'}{\sqrt{1+(y')^2}} &= 0 \\
\Rightarrow\qquad && \dv{x}\,\frac{f'(x)}{\sqrt{1+(f'(x))^2}} &= 0 \\
\Rightarrow\qquad && \int_b^a \dv{x} \frac{f'(x)}{\sqrt{1+(f'(x))^2}}\,\dd x &= \text{constant} = C \\
\Rightarrow\qquad && f'(x) &= \frac{C}{\sqrt{1-C^2}} = m \\
\end{alignat}
\end{document}


Further information about advanced math typesetting can be found in the »Math mode« document.

-

One possible solution:

\documentclass{article}

\usepackage{amsmath}

\newcommand*\differential[1]{\mathop{}\!\mathrm{d}#1}
\newcommand*\diff[3][\differential]{\frac{#1#2}{#1#3}}

\begin{document}

\begin{alignat}{2}
&&\diff{}{x}\frac{y'}{\sqrt{1+(y')^{2}}}
&= 0\\
&\Rightarrow
&\diff{}{x}\frac{f'(x)}{\sqrt{1+(f'(x))^{2}}}
&= 0\\
&\int_{b}^{a} \diff{}{x}\frac{f'(x)}{\sqrt{1+(f'(x))^{2}}} \differential{x}
&= \text{constant}
= C\\
&\Rightarrow
&f'(x)
&= \frac{C}{\sqrt{1-C^{2}}}
= m\\
&\Rightarrow
&f(x)
&= mx + \text{constant}
\end{alignat}

\end{document}


Note: Remove the \mathrm if you don't want the differential d to be upright.

(Remember to Avoid eqnarray!.)

Update

If you want vertical arrows between the equations, you can use the following:

\documentclass{article}

\usepackage{mathtools}

\newcommand*\differential[1]{\mathop{}\!\mathrm{d}#1}
\newcommand*\diff[3][\differential]{\frac{#1#2}{#1#3}}
\newcommand*\arrowDown{\ArrowBetweenLines[\Downarrow]}

\begin{document}

\begin{alignat}{2}
&&\diff{}{x}\frac{y'}{\sqrt{1+(y')^{2}}}
&= 0\\
\arrowDown
&&\diff{}{x}\frac{f'(x)}{\sqrt{1+(f'(x))^{2}}}
&= 0\\
\arrowDown
&&\int_{b}^{a} \diff{}{x}\frac{f'(x)}{\sqrt{1+(f'(x))^{2}}} \differential{x}
&= \text{constant}
= C\\
\arrowDown
&&f'(x)
&= \frac{C}{\sqrt{1-C^{2}}}
= m\\
\arrowDown
&&f(x)
&= mx + \text{constant}
\end{alignat}

\end{document}


-

you are already using amsmath:

\documentclass[11pt]{article}
\usepackage{amsmath}

\begin{document}
\begin{align}
\dfrac{d }{dx} \dfrac{y'}{\sqrt{1+(y')^2}}       &= 0\\
\Rightarrow \dfrac{d }{dx} \dfrac{f'(x)}{\sqrt{1+(f'(x))^2}} &=0\\
\Rightarrow \displaystyle\int_b^a \dfrac{d }{dx} \dfrac{f'(x)}{\sqrt{1+(f'(x))^2}} \,dx &= constant = C\\
\Rightarrow f'(x) = \dfrac{C}{\sqrt{1-C^2}}                  &= m\\
\Rightarrow \quad f(x)                                       &= mx+ \text{constant}
\end{align}
\end{document}


or

  \begin{align}
&&\dfrac{d }{dx} \dfrac{y'}{\sqrt{1+(y')^2}} &= 0\\
\Rightarrow &&\dfrac{d }{dx} \dfrac{f'(x)}{\sqrt{1+(f'(x))^2}} &=0\\
\Rightarrow &&\displaystyle\int_b^a \dfrac{d }{dx} \dfrac{f'(x)}{\sqrt{1+(f'(x))^2}} \,dx &= constant = C\\
\Rightarrow &&f'(x) = \dfrac{C}{\sqrt{1-C^2}} &= m\\
\Rightarrow &&\quad f(x) &= mx+ \text{constant}
\end{align}


The & character is used for the horizontal alignment. See http://mirror.ctan.org/info/math/voss/mathmode/Mathmode.pdf

By the way: eqnarray has the syntax: left & middle & right

-