# Aligning 3 columns in LaTeX eqnarray

I have the following LaTeX eqnarray:

\begin{eqnarray}
\int ( D \frac{d^2 P(x)}{dx^2}-\frac{d}{dx}[u(x)P(x)] ) & = & \int 0 \Leftrightarrow \\
D \frac{d}{dx} P(x) - u(x)P(x) & = & C \Leftrightarrow \\
D \frac{d}{dx} P(x) - K_0P(x) - \frac{K_1}{x}P(x) & = & C \Leftrightarrow \\
\frac{dP(x)}{dx} - k_0P(x) - \frac{k_1}{x} P(x) & = & C,
\end{eqnarray}

With this outcome:

Is it possible to align my \Leftrightarrow in a 3rd column?

-

## migrated from stackoverflow.comNov 28 '12 at 1:53

This question came from our site for professional and enthusiast programmers.

## 2 Answers

You should avoid eqnarray. See \eqnarray vs \align.

I'd recommend using align or alignat from amsmath package:

Both align and alignat provide pairs of rl alignment columns. So, I used a && before the \Leftrightarrow assuming that the next column was to be right aligned.

## Code:

\documentclass{article}
\usepackage{amsmath}

\begin{document}\noindent
Using \verb|align|:
\begin{align}
\int ( D \frac{d^2 P(x)}{dx^2}-\frac{d}{dx}[u(x)P(x)] ) &= \int 0 &&\Leftrightarrow \\
D \frac{d}{dx} P(x) - u(x)P(x)                          &= C      &&\Leftrightarrow \\
D \frac{d}{dx} P(x) - K_0P(x) - \frac{K_1}{x}P(x)       &= C      &&\Leftrightarrow \\
\frac{dP(x)}{dx} - k_0P(x) - \frac{k_1}{x} P(x)         &= C,
\end{align}
Using \verb|alignat|:
\begin{alignat}{4}
\int ( D \frac{d^2 P(x)}{dx^2}-\frac{d}{dx}[u(x)P(x)] ) &= \int 0 &&\Leftrightarrow \\
D \frac{d}{dx} P(x) - u(x)P(x)                          &= C      &&\Leftrightarrow \\
D \frac{d}{dx} P(x) - K_0P(x) - \frac{K_1}{x}P(x)       &= C      &&\Leftrightarrow \\
\frac{dP(x)}{dx} - k_0P(x) - \frac{k_1}{x} P(x)         &= C,
\end{alignat}
\end{document}
-

The equationarray doesn't allow more than 3 columns, but you can get what you want with the array environment.

$\begin{array}{cccc} \int ( D \frac{d^2 P(x)}{dx^2}-\frac{d}{dx}[u(x)P(x)] ) & = & \int 0 & \Leftrightarrow \\ D\frac{d}{dx} P(x) - u(x)P(x) & = & C & \Leftrightarrow \\ D\frac{d}{dx} P(x) - K_0P(x) - \frac{K_1}{x}P(x) & = & C & \Leftrightarrow \\ \frac{dP(x)}{dx} - k_0P(x) - \frac{k_1}{x} P(x) & = & C &, \end{array}$

If you dont like the alignment obtained you can modify it for example replacing {cccc} with {rclr}, or whatever you prefer.

-
Thanks. That does it. But now the lines are interpreted as text lines (with smaller fractions, integrals, etc.) - is there a way to change it to normal? I know I could use dfrac but how about the integrals? –  Caspar Aleksander Bang Jespers Nov 26 '12 at 12:29
I just edited. Now you can avoid \dfrac. –  888 Nov 26 '12 at 13:49
array for equations is just a written-out form of the mistakes of eqnarray — use the amsmath environments mentioned in Peter Grill’s answer. –  wasteofspace Nov 28 '12 at 11:38