# Long division spacing

Original thread. I want to make the long division represented with floating point, but i have strange results. The numbers are not aligned (with yellow). And some numbers are far away(red).

\documentclass{article}
\usepackage[TABcline]{tabstackengine}
\TABstackMath
\renewcommand\stackalignment{l}
\newcommand\lminus{\llap{$-$}}
{\catcode-=\active
\gdef -{\lminus}}
\newcommand\minusactive{\phantom{-}\catcode-=\active}
\setstacktabbedgap{3pt}
\begin{document}
\begin{tabular}{ll@{\hspace{10ex}}c}

$\minusactive \tabbedShortunderstack[r]{ &7,&6&2&4&:4=1,815\\ -&4&& &&&\\ \TABcline{2,3} & &3&2&&&&\\ &-&3&2&&&&\\ \TABcline{3,4} & & & &6& &&\\ & & &-&4& &&\\ \TABcline{5} & & & & 2&0&\\ & & & -& 2&0&\\ \TABcline{5} & & & &0& }$

\end{tabular}
\end{document}

• Just out of curiosity -- Why did you set the result of the division to 1815 rather 1906? – Mico Dec 30 '18 at 23:48
• You are right. The number is 7,26 not 7,246... Again making mistake for fast MEW. – Simeon Simeonov Dec 31 '18 at 1:10

Like this?

\documentclass{article}
\usepackage[TABcline]{tabstackengine}
\TABstackMath
\renewcommand\stackalignment{l}
\newcommand\lminus{\llap{$-$}}
{\catcode-=\active
\gdef -{\lminus}}
\newcommand\minusactive{\phantom{-}\catcode-=\active}
\setstacktabbedgap{3pt}

\begin{document}

\begin{tabular}{ll@{\hspace{10ex}}c}
$\minusactive \tabbedShortunderstack[r]{ &7\rlap{,}&6&2&4&:4=1,815\\ -&4&& &&&\\ \TABcline{2,3} & &3&2&&&&\\ &-&3&2&&&&\\ \TABcline{3,4} & & & &6& &&\\ & & &-&4& &&\\ \TABcline{5} & & & & 2\rlap{$\; 0 $}&&\\ & & & -& 2\rlap{$\; 0 $}&&\\ \TABcline{5} & & & &0& }$
\end{tabular}

\end{document}


If you don't need to show the thousands-separator symbol (here: ,), the layout becomes much easier, and the typographic problem can be solved using just an array environment.

\documentclass{article}
\usepackage{array} % for '\newcolumntype' macro
\newcolumntype{C}{>{{}}c<{{}}}
\usepackage{mathtools} % for '\mathllap' macro
\begin{document}
$\setlength\arraycolsep{0.5pt} % default: 5pt \begin{array}[t]{@{} C @{} *{4}{c} CcC *{4}{c} @{}} &7&6&2&4 &:&4&=& 1&9&0&6\\ -&4 \\ \cline{2-2} &3&6 \\ -&3&6 \\ \cline{2-3} & &0&2 \\ & &\mathllap{-}&0 \\ \cline{4-4} & & &2&4\\ & &\mathllap{-}&2&4\\ \cline{4-5} & & & &0\rlap{.} % "\rlap{.}" is optional \\ \cline{5-5} % optional \end{array} \qquad \begin{array}[t]{@{} C @{} *{4}{c} CcC *{4}{c} @{}} &7&2&6&0 &:&4&=& 1&8&1&5\\ -&4 \\ \cline{2-2} &3&2 \\ -&3&2 \\ \cline{2-3} & &0&6 \\ & &\mathllap{-}&4 \\ \cline{4-4} & & &2&0\\ & &\mathllap{-}&2&0\\ \cline{4-5} & & & &0\rlap{.} % "\rlap{.}" is optional \\ \cline{5-5} % optional \end{array}$
\end{document}

• The comma may have had the meaning of a decimal point, conventions vary. – Carsten S Dec 31 '18 at 10:54