# Relational Operator spacing problem with alignat

I have not asked a really embarrassing question in a while, so thought it was time :-). I am stumped as to why the spacing around the = on the third line is incorrect:

## Notes:

• I realize I am cheating a bit on the second line, but I don't mind that the equation starts a bit on the left.
• The absolute value is from Absolute Value Symbols, but is not relevant to this problem.

## Code:

\documentclass{article}
\usepackage{mathtools}

% http://tex.stackexchange.com/questions/43008/absolute-value-symbols
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%

%% ----- Not relevant for this example
%% Swap the definition of \abs* and \norm*, so that \abs
%% and \norm resizes the size of the brackets, and the
%% starred version does not.
%\makeatletter
%\let\oldabs\abs
%\def\abs{\@ifstar{\oldabs}{\oldabs*}}

\begin{document}
\begin{alignat*}{5}
\abs{E_T}
&&                  {}\le \frac{K (b-a)^3}{12 n^2} &&= 0.005 \\
&&  \frac{0.2487 (\pi)^3}{12 n^2}                  &&= 0.005 \\
\implies &&                                            n^2  &&=128.52 \\
&&                                            n    &&\approx 11.34
\end{alignat*}
\end{document}

-

With alignat with 5 alignments you are using an rl-style alignment and, using your third row, this results in

       r & l &   r & l & r
\implies &   & n^2 &   & r


That is, both n^2 and =128.52 are right-aligned. Using &&& as the last set of alignments works:

\documentclass{article}
\usepackage{mathtools}

% http://tex.stackexchange.com/questions/43008/absolute-value-symbols
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%

\begin{document}
\begin{alignat*}{5}
\abs{E_T}
&&                  {}\le \frac{K (b-a)^3}{12 n^2} &&&= 0.005 \\
&&  \frac{0.2487 (\pi)^3}{12 n^2}                  &&&= 0.005 \\
\implies &&                                            n^2  &&&=128.52 \\
&&                                            n    &&&\approx 11.34
\end{alignat*}
\end{document}

-
But then why is that not a problem in the last line? – Peter Grill Mar 20 '14 at 23:09
The last line contains 6 "characters" (\approx, and 11.34), just like the first two (= and 0.005), so they line up using a right alignment. – Werner Mar 20 '14 at 23:13
Yep, that makes sense. Thanks. – Peter Grill Mar 20 '14 at 23:13

So much less hair pulling with a TABstack:

\documentclass{article}
\usepackage{mathtools}
\usepackage{tabstackengine}
\stackMath

% http://tex.stackexchange.com/questions/43008/absolute-value-symbols
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%

%% ----- Not relevant for this example
%% Swap the definition of \abs* and \norm*, so that \abs
%% and \norm resizes the size of the brackets, and the
%% starred version does not.
%\makeatletter
%\let\oldabs\abs
%\def\abs{\@ifstar{\oldabs}{\oldabs*}}

\begin{document}
\setstacktabulargap{0pt}
\setstackgap{S}{6pt}
\tabularShortstack{rrl}{
\abs{E_T}
&                  {}\le \dfrac{K (b-a)^3}{12 n^2} =& 0.005 \\
&  \dfrac{0.2487 (\pi)^3}{12 n^2}                  =& 0.005 \\
\implies &                                            n^2  =&128.52 \\
&                                            n    \approx& 11.34
}
\end{document}


-