# Vertically Aligning Multiple Symbols in Each Row

In the following MWE, I want the \implies symbols to be aligned, and both \leq symbols on each row to be aligned (adding space between everything as necessary).

How can I add & symbols in the align* code to make this happen?

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
|p - q| \leq M
& \implies -M \leq p - q \leq M \\
& \implies q - M \leq p \leq q + M
\end{align*}
\end{document}


To be clear, I want the output to look like this (just substitute \leq for each <):

|p - q| < M ==>  - M  < p - q <  M
==> q - M <   p   < q + M

-

Depending on the kind of alignment desired you have several options: the alignat environment from amsmath, an array, or to use \phantom to add spacing:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{alignat*}{3}
|p - q| \leq M
& \implies -M && \leq p - q && \leq M \\
& \implies q - M && \leq p && \leq q + M
\end{alignat*}

$\begin{array}{c@{\ \implies\ }c@{\ \leq\ }c@{\ \leq\ }c} |p - q| \leq M & -M & p - q & M \\ & q - M & p & q + M \end{array}$

\begin{align*}
|p - q| \leq M
& \implies \phantom{q}-M \leq p - q \leq \phantom{q+{}}M \\
& \implies q - M \leq p\phantom{{}-q} \leq q + M
\end{align*}

\end{document}


And here's how to obtain the alignment required in a comment, using a macro \centerto which makes a nice use of \ooalign; the macro was defined here at c.t.t by Enrico Gregorio:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\centerto}[2]{%
{\ooalign{$\displaystyle\hphantom{#2}$\cr
\hidewidth$\displaystyle#1$\hidewidth\cr}}}

\begin{document}

\begin{align*}
|p - q| \leq M
& \implies \centerto{-M}{q-M} \leq p - q \leq \centerto{M}{q+M} \\
& \implies q - M \leq \centerto{p}{p-q} \leq q + M
\end{align*}

\end{document}


-
Your second option provides exactly the option I was looking for. Thank you! P.S. Is there any way to achieve a similar result using the \align environment? –  jamaicanworm Mar 19 '12 at 16:42
@jamaicanworm see the Solution II in my answer (it's the other one). –  yo' Mar 19 '12 at 16:59
@jamaicanworm: sure; see my updated answer. –  Gonzalo Medina Mar 19 '12 at 17:18

You could use the alignat environment (also from the amsmath package)

Note that (from the documentation)

This environment takes one argument, the number of “equation columns”: count the maximum number of &s in any row, add 1 and divide by 2.

In this case, there are 5 & in each row, so adding 1 and dividing by 2 gives {3} equation columns. Note that I've used {} to get correct spacing around the \leq symbols

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{3}
|p - q| \leq M & \implies -M    &{}\leq{} & p - q & {}\leq {}& M \\
& \implies q - M &{}\leq{} & p     & {}\leq {}& q + M
\end{alignat*}
\end{document}


Here's another option using the array environment, but I think Gonzalo's array answer gives better spacing

\documentclass{article}
\usepackage{array}
\usepackage{amsmath}
\begin{document}

$\begin{array}{*{7}{c}} |p - q| \leq M & \implies & -M &\leq & p - q &\leq & M \\ & \implies & q - M &\leq & p &\leq & q + M \end{array}$
\end{document}

-
As with tohecz's solution, this doesn't work perfectly, since the p is not centered between the two \leq symbols... –  jamaicanworm Mar 19 '12 at 16:40
@jamaicanworm see my edit –  cmhughes Mar 19 '12 at 16:51
This way, it has quite wrong spacing (too wide). The @GonzaloMedina 's solution is much closer to the correct spacing (as can be seen by comparing his 2nd solution with his 1st and 3rd ones, the 2nd one is a bit wider, but very close to the other ones). –  yo' Mar 19 '12 at 17:12
@tohecz yes, which is why I clearly stated that Gonzalo's array answer gives better spacing –  cmhughes Mar 19 '12 at 17:54
My apologies, I missed that. –  yo' Mar 19 '12 at 18:49

You can use \phantom to make something "invisible". Just notice the necessary empty brackets {} after + and before -, without them the +/- sign behaves like "unary operator" and gets different spacing.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
|p - q| \leq M
& \implies \phantom{q}-M \leq p - q \leq \phantom{q+{}}M \\
& \implies q - M \leq p\phantom{{}-q} \leq q + M
\end{align*}
\end{document}


## Solution II: centered

You can you the \mathclap macro from mathtools twice to get it centered. I made a command \mathcenterto that takes two arguments: 1st to determine the correct width and 2nd to be typeset. See the following code:

\documentclass{article}
\usepackage{amsmath}

% YOU NEED THESE TWO LINES:
\usepackage{mathtools}
\def\mathcenterto#1#2{\mathclap{\phantom{#1}\mathclap{#2}}\phantom{#1}}

\begin{document}

\begin{align*}
|p - q| \leq M
& \implies \mathcenterto{q-M}{-M} \leq p - q \leq \mathcenterto{q+M}{M} \\
& \implies q - M \leq \mathcenterto{p-q}{p} \leq q + M
\end{align*}

\end{document}

-
But then the p is not centered between the two \leq symbols... –  jamaicanworm Mar 19 '12 at 16:39
I know. It's a matter of taste. You seem to want to have the \leq aligned to show the correspondence. This just ephasizes that p is the same one in the upper and the lower ineqality. –  yo' Mar 19 '12 at 16:49
I added Solution II that makes it 1) centered 2) with the origninal align* envrionment. –  yo' Mar 19 '12 at 17:04