2

I have posted this and this later item on long division.

I thought what appears below worked perfectly. But only today I tried it with an example that has several digits before the decimal point in the quotient, and it's lousy.

So I have two questions:

  • How do we make it work well with several digits before the decimal point in the quotient? This I could possibly figure out with further skull sweat, but I am reluctant to undertake that without a good answer to the next question, which goes beyond my present competence.

  • How do we make it into a user-friendly style file, so the user only needs to enter the numbers with some indication of what the role of each of them is in the long-division process?

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
% \usepackage{xcolor}
\usepackage{array, booktabs}
\parindent=0pt
\pagestyle{empty}

\begin{document}

\[
\begin{array}{ rr@{} %>{\color{red}}
c@{}*{6}{c@{\mkern2mu}} }
& 0 & . & 7 & 1 & 6 & 2 \\ \cmidrule[0.6pt](l{-0.385em}){2-8}\\[-16.9pt]
74\;\rlap{\Large)} &53 & . & 0 & 0 & 0 & 0 & 0 \\
& 51 & & 8 \\ \cmidrule(l{1ex}){2-5}
& 1 & & 2 & 0 \\
& & & 7 & 4 \\ \cmidrule{3-6}
& & & 4 & 6 & 0 \\
& & & 4 & 4 & 4 \\ \cmidrule{4-7}
& & & & 1 & 6 & 0 \\
& & & & 1 & 4 & 8 \\ \cmidrule{5-8}
& & & & & 1 & 2 & 0
\end{array}
\]

\[
\begin{array}{ rr@{} %>{\color{red}}
c@{}*{8}{c@{\mkern2mu}} }
& 101 & . & 8 & 0 & 2 & 0 & 8 & 3 \\ \cmidrule[0.6pt](l{-0.385em}){2-8}\\    [-16.9pt]
96\;\rlap{\Large)} &9773 & . & 0 & 0 & 0 & 0 & 0 \\
& 96\phantom{00} & &  \\ \cmidrule(l{1ex}){2-2}
& 17\phantom{0} & & \\
&  0\phantom{0} \\ \cmidrule(l{1ex}){2-2}
& 173 \\
&  96 \\ \cmidrule(l{1ex}){2-3}
& 77 & & 0 \\
& 76& & 8 \\ \cmidrule(l{1ex}){2-4}
& & & 2 & 0 \\
& & & & 0 \\ \cmidrule{3-5}
& & & 2 & 0 & 0 \\
& & & 1 & 9 & 2 \\ \cmidrule{3-6}
& & & & & 8 & 0 \\
& & & & & & 0 \\ \cmidrule{6-7}
& & & & & 8 & 0 & 0 \\
& & & & & 7 & 6 & 8 \\ \cmidrule{6-8}
& & & & & & 3 & 2 & 0 \\
& & & & & & 2 & 8 & 8 \\ \cmidrule{7-9}
& & & & & & & 3 & 2 & 0
\end{array}
\]

\end{document}
egreg
  • 1,121,712

1 Answers1

1

I had to do a long division for a Dutch textbook on digital design. I also used this method to do a long division on binary numbers. The trick is to use hidden character to indent numbers to the right position. The macro \ph{} takes care of this. Note that the comments are in Dutch:

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{mathtools}
\usepackage{xcolor}

%% Print hidden characters by using the white color, used for aligning numbers.
%% Please note that the dash must cast to mathbin. See:
%% http://tex.stackexchange.com/questions/21598/how-to-color-math-symbols
\newcommand\ph[1]{\if-#1\mathbin{\textcolor{white}{-}}\else\textcolor{white}{#1}\fi}

\begin{document}

\begin{equation*}
\setlength{\jot}{0pt}
\begin{split}
                                  &12345.67 \div 25 = 493.8268 \leftrightarrow \text{quoti\"ent}\\
\text{viermaal aftrekken}\qquad  &\underline{100}\ - \\
                                  &\ph{0}234 \\
\text{negenmaal aftrekken}\qquad &\ph{0}\underline{225}\ - \\
                                  &\ph{000}95 \\
\text{driemaal aftrekken}\qquad  &\ph{000}\underline{75}\ - \\
                                  &\ph{000} 20\ph{.}6 \\
\text{achtmaal aftrekken}\qquad  &\ph{000}\underline{20\ph{.}0}\ - \\
                                  &\ph{00000.}67 \\
\text{tweemaal aftrekken}\qquad  &\ph{00000.}\underline{50}\ - \\
                                  &\ph{00000.}170 \\
\text{zesmaal aftrekken}\qquad   &\ph{00000.}\underline{150}\ - \\
                                  &\ph{00000.0}200 \\
\text{achtmaal aftrekken}\qquad  &\ph{00000.0}\underline{200}\ - \\
                                  &\ph{00000.000}0 \leftrightarrow \text{rest} \\
\end{split}
\end{equation*}

\end{document}