29

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.

  • 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 02 '13 at 00:07
  • 2
    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 02 '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 06 '17 at 21:27

9 Answers9

28

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

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
kmacinnis
  • 1,655
  • 6
    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! – Hood Chatham Oct 22 '17 at 15:24
20

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

Gonzalo Medina
  • 505,128
  • @Gonzalo_Medina Thanks for the answer, how would I write numbers on top of the line? – Jamie Twells Dec 30 '14 at 16:50
  • Never mind, like this: $$ \begin{array}{r} 0 \\ \Mydiv{8}{3} \end{array}$$ and remove all the $ from the command :) – Jamie Twells Dec 30 '14 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 '15 at 05:55
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

Harry
  • 171
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}

Jeff
  • 703
3

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

dax
  • 91
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

0

I found that one can adjust the spacing 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. I scaled up the size of the parentheses to make it look better, as barbara beeton commented on the question.

0

What about polynom package. If you write

\longdiv{12345}{13}

You obtain enter image description here

Luis Turcio
  • 2,757