# Better way to display long division?

I'm currently in the process of trying to create a worksheet for my students with long division problems for them to practice. Unfortunately, the best I've been able to come up with so far in terms of displaying long division like how they write it is:

Which could work if need be, but I thought I'd see if anyone has tooled around with this and come up with something better. To create that, all I did was type:

$\overline{)12345}$


Any suggestions for ways of making that better (so it looks more like what'd you see when using \longdiv) would be awesome.

• I'm not somewhere I can check, but if I remember correctly, kicking up the parenthesis by one size improves the appearance. a solution was published in tugboat years ago. – barbara beeton Sep 2 '13 at 0:07
• To add to Barbara's comment: here is what I did: \newcommand[2]{\longdiv}{#1\ \overline{\smash{\Big)}\ #2}} and it closed the gap. – user28549 Sep 2 '14 at 21:24
• Using \overlinegenerally does not produce pretty results with shorter characters. This applies to many of the answers given below. – Andrew Uzzell Jan 6 '17 at 21:27

## 8 Answers

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}


• @Gonzalo_Medina Thanks for the answer, how would I write numbers on top of the line? – Jamie Twells Dec 30 '14 at 16:50
\end{document}


• It would be nice if you make your example compilable, so people can just copy/paste to try it. – Phelype Oleinik May 20 '19 at 7:30
• Good call. All fixed. – jackw11111 May 20 '19 at 7:42
• Thanks :-) Note that \scalebox is provided by graphicx, so you don't need all of TikZ to use it. I edited it for you. – Phelype Oleinik May 20 '19 at 7:44
• Yes, I didn't know why it needed tikz just that it worked. Thanks. – jackw11111 May 20 '19 at 7:44

I combined several ideas from the other answers on this page with some from this page to write long division for generating power series.

It's not perfect, but it's good enough for my purposes. Here's the Fibonacci sequence:

\documentclass{article}
\usepackage{amsmath}
\usepackage{scalerel}
\setcounter{MaxMatrixCols}{20}

\newcommand{\longdiv}{\smash{\mkern-0.43mu\vstretch{1.31}{\hstretch{.7}{)}}\mkern-5.2mu\vstretch{1.31}{\hstretch{.7}{)}}}}
\begin{document}

$\arraycolsep=1pt \renewcommand\arraystretch{1.2} \begin{array}{*1r @{\hskip\arraycolsep}c@{\hskip\arraycolsep} *{11}r} & & 1 & + & x & + & 2x^2 & + & 3x^3 & + & 5x^4 & + & \dots \\ \cline{2-13} 1-x-x^2 & \longdiv & 1 & & & & & & & & & & \\ & & 1 & - & x & - & x^2 & & & & & & \\ \cline{3-7} & & & & x & + & x^2 & & & & & & \\ & & & & x & - & x^2 & - & x^3 & & & & \\ \cline{5-9} & & & & & & 2x^2 & - & x^3 & & & & \\ & & & & & & 2x^2 & - & 2x^3 & - & 2x^4 & & \\ \cline{7-11} & & & & & & & & 3x^3 & + & 2x^4 & & \\ & & & & & & & & 3x^3 & - & 3x^4 & - & 3x^5 \\ \cline{9-13} & & & & & & & & & & 5x^4 & + & 3x^5 \\ & & & & & & & & & & & & \vdots \\ \end{array}$

\end{document}


Here is a way to display 2011/3:

\begin{align*}
&\text{ }\text{ }\text{ }670\\
3 &\overline{\big)2011}\\
&\underline{\text{ }18}\\
&\text{ }\text{ }\text{ }21\\
&\text{ }\text{ }\underline{\text{ }21}\\
&\text{ }\text{ }\text{ }\text{ }\text{ }\text{ }1
\end{align*}


Tweak the spacing on different long divisions. As barbara beeton commented on the question, scaling up the size of the parentheses does help.

What about polynom package. If you write

\longdiv{12345}{13}


You obtain