Better way to display long division?

\smash the right paren, so that it doesn't push up the \overline:``

\documentclass{article}
\newcommand\showdiv[1]{\overline{\smash{)}#1}}
\begin{document}
\(\showdiv{12345} \)
\end{document}

enter image description here

If you don't like the curvature of the right paren, you can squeeze it a bit (here, I squeezed it perhaps a bit too much, to 50% of its original width, just to demonstrate)

\documentclass{article}
\usepackage{scalerel}
\newcommand\showdiv[1]{\overline{\smash{\hstretch{.5}{)}}#1}}
\begin{document}
\(\showdiv{12345} \)
\end{document}

enter image description here

And if you are concerned that squeezing the glyph horizontally makes the stroke too thin, then just nearly overlay two of them:

\documentclass{article}
\usepackage{scalerel}
\newcommand\showdiv[1]{\overline{\smash{\hstretch{.5}{)}\mkern-3.2mu\hstretch{.5}{)}}#1}}
\begin{document}
\(\showdiv{12345} \)
\end{document}

enter image description here

And, to add the finishing touches:

\documentclass{article}
\usepackage{scalerel}
\usepackage{stackengine}
\usepackage{xcolor}
\newcommand\showdiv[1]{\overline{\smash{\hstretch{.5}{)}\mkern-3.2mu\hstretch{.5}{)}}#1}}
\newcommand\ph[1]{\textcolor{white}{#1}}
\begin{document}
\setstackgap{S}{1.5pt}
\stackMath\def\stackalignment{r}
\(
\stackunder{%
  5 \stackon[1pt]{\showdiv{12345}}{2469}%
}{%
  \Shortstack[l]{{\underline{10}} \ph{1}23 {\ph{1}\underline{20}} \ph{12}34 {\ph{12}\underline{30}} %
   \ph{123}45 {\ph{123}\underline{45}} \ph{1234}0}%
}
\)
\end{document}

enter image description here


I got really prefectionisty about this once upon a time, and created a tikz-based solution:

\documentclass[border=4pt]{standalone}
\usepackage{calc}
\usepackage{tikz}

\newcommand{\longdivision}[2]{
    \settowidth{\dividendlength}{#1}
    \settowidth{\divisorlength}{#2}
    \settoheight{\dividendheight}{#1}
    \settoheight{\maxheight}{#1#2}
    \settoheight{\divisorheight}{#2}

    \begin{tikzpicture} [baseline=.5pt]
        \node at (-.5*\divisorlength-1pt,.5*\divisorheight) {#2};
        \node at (.5*\dividendlength+5pt,.5*\dividendheight) {#1};
        \draw [thick]  (0pt,-.22*\dividendheight) arc (-70:60:\maxheight*.41 and \maxheight*.82) -- ++(\dividendlength+7pt,0pt);
    \end{tikzpicture}
}

\newlength{\dividendlength}
\newlength{\divisorlength}
\newlength{\dividendheight}
\newlength{\divisorheight}
\newlength{\maxheight}

\begin{document}

\longdivision{$x^2+3x-5$}{$x-3$}

\end{document}

polynomial long division

I'm sure it could be improved upon, but I was happy enough with this (and never was happy with the paren + overline solutions).


You can give a definition of a command inspired by the one used in longdiv.sty; something along these lines:

\documentclass{article}

\newcommand\Mydiv[2]{%
$\strut#1$\kern.25em\smash{\raise.3ex\hbox{$\big)$}}$\mkern-8mu
        \overline{\enspace\strut#2}$}

\begin{document}

\Mydiv{56}{3678}\quad\Mydiv{3}{37678}

\end{document}

enter image description here

Tags:

Formatting