How to draw polynom division?
Is (local) layout important?
Typesetting polynom division can easy be done with the polynom
package:
\documentclass{article}
\usepackage{polynom}
\begin{document}
\textbf{Style A:}\par % this is the default
\polylongdiv[style=A]{6x^3-2x^2+x+3}{x^2-x+1}
\textbf{Style B:}\par
\polylongdiv[style=B]{6x^3-2x^2+x+3}{x^2-x+1}
\textbf{Style C:}\par
\polylongdiv[style=C]{6x^3-2x^2+x+3}{x^2-x+1}
\end{document}
I'm afraid I didn't try to change layout (yet), but that will be another question...
Since the structure lends itself to an array
, here is such an elementary implementation:
\documentclass{article}
\newcommand{\dropsign}[1]{\smash{\llap{\raisebox{-.5\normalbaselineskip}{$#1$\hspace{2\arraycolsep}}}}}%
\begin{document}
\[
\begin{array}{r|r}
\dropsign{-} 6x^3 - 2x^2 + \phantom{6}x + 3 & x^2 - \phantom{6}x + 1 \\ \cline{2-2}
6x^3 - 6x^2 + 6x \phantom{{}+3} & 6x + 4 \\ \cline{1-1} \\[\dimexpr-\normalbaselineskip+\jot]
\dropsign{-} 4x^2 - 5x + 3 \\
4x^2 - 4x + 4 \\ \cline{1-1} \\[\dimexpr-\normalbaselineskip+\jot]
- x - 1
\end{array}
\]
\end{document}
For fun with TikZ.
Explanation: \phantom
is used to vertically align x
, x^2
, x^3
, etc.
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[yscale=.5]
\def\c{2}
\draw[blue,thick]
(0,.5)--+(-90:5)
(0,-.5)--+(0:2)
(0,-1.5)--+(180:3)
(0,-3.5)--+(180:2);
\path[left]
(0,0) node{$6x^3-2x^2+\phantom{6}x+3$}
++(-90:1) node{$6x^3-6x^2+6x\phantom{{}+3}$}
++(-90:1) node{$4x^2-5x+3$}
++(-90:1) node{$4x^2-4x+4$}
++(-90:1) node{$-x-1$};
\path[left,magenta]
(0,-.5) +(180:.2) node{$-$\phantom{$6x^3-2x^2+\phantom{6}x+3$}}
(0,-2.5) +(180:.2) node{$-$\phantom{$4x^2-5x+3$}};
\path[left]
(\c,0) node{$x^2-\phantom{6}x+1$}
+(-90:1) node{$6x+4$};
\end{tikzpicture}
\end{document}