28

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:

example

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.

3
  • 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. Sep 2, 2013 at 0:07
  • 1
    To add to Barbara's comment: here is what I did: \newcommand[2]{\longdiv}{#1\ \overline{\smash{\Big)}\ #2}} and it closed the gap.
    – TJJ
    Sep 2, 2014 at 21:24
  • Using \overlinegenerally does not produce pretty results with shorter characters. This applies to many of the answers given below. Jan 6, 2017 at 21:27

9 Answers 9

19

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

3
  • @Gonzalo_Medina Thanks for the answer, how would I write numbers on top of the line? Dec 30, 2014 at 16:50
  • Never mind, like this: $$ \begin{array}{r} 0 \\ \Mydiv{8}{3} \end{array}$$ and remove all the $ from the command :) Dec 30, 2014 at 17:27
  • Nice looking long division symbol... now, please convince the owner of polynom package to fix it so long division doesn't negate all the products on each line. :D
    – Jeff
    Oct 25, 2015 at 5:55
26

\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}}
\let\ph\phantom
\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

24

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).

1
  • 4
    I'm going to steal this and put it in my package longdivision.sty (with reference to this post of course) unless anyone has an objection. Thanks! Oct 22, 2017 at 15:24
7

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}

enter image description here

1
  • Best typesetting of all the answers. But keeping track of all those &'s is not easy. Jan 10 at 14:18
4

You can use the longdiv "package". I put package in quotes because loading it using \usepackage{} doesn't work and for whatever reason, you have to load it using \input longdiv.tex.

Then you can do long division using \longdiv{6584}{28}.

After that, you can use package polynom to do polynomial long division as \polylongdiv{x^2+2x+4}{x-1}

0
2

there is packaged named "longdivision". it works perfect for this purpose.

Longdivision package provides two commands: \longdivision and \intlongdivision.

if we write \intlongdivision{12345}{13} we get this: enter image description here

1

One use case with minimal features (might need to play around with the exact numbers):

\documentclass{article}
\usepackage{graphicx}
\begin{document}
  $x+1\scalebox{1.2}{)}\hspace{-0.35em}\overline{\hspace{0.5em} x^2}$
\end{document}

enter image description here

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

What about polynom package. If you write

\longdiv{12345}{13}

You obtain enter image description here

1
  • 1
    It's not working for me. Oct 3, 2022 at 15:56
0

Here is a way to display 2011/3 using \text{ } spaces:

\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*}

enter image description here

You can tweak the spacing and the numbers for different long divisions. As barbara beeton commented on the question, scaling up the size of the parentheses does help, and that is what I did here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .