6

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:

enter image description here

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}

% https://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}

Peter Grill
  • 223,288

2 Answers2

5

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:

enter image description here

\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}
Werner
  • 603,163
2

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}

enter image description here