Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

% 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}
share|improve this question

2 Answers 2

up vote 5 down vote accepted

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}
share|improve this answer
    
But then why is that not a problem in the last line? –  Peter Grill Mar 20 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 at 23:13
    
Yep, that makes sense. Thanks. –  Peter Grill Mar 20 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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.