23

I want to draw this scheme, but I do not know how to start. Please help me.

enter image description here

5
  • 8
    On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are "too localized". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. Oct 26, 2012 at 14:58
  • 5
    Do you need to set it up exactly like that, or could you use the polynom package? See the manual and the demofile, polydemo.pdf. Oct 26, 2012 at 15:41
  • Following up Andrew's comment: Why don't you just change the title to something related to "polynom division", provide some context, and mention what you have already tried?
    – krlmlr
    Oct 26, 2012 at 17:04
  • Why do you want to use TikZ to typeset a polynomial division problem? Oct 26, 2012 at 19:46
  • It would be helpful if you showed what you have tried so far in the way of a MWE. While solving problems is fun, setting them up is not. Then those trying to help can simply cut and paste your MWE and get started on solving problem. Oct 26, 2012 at 20:50

4 Answers 4

38

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}

\textbf{Style D:}\par
\polylongdiv[style=D]{6x^3-2x^2+x+3}{x^2-x+1}
\end{document}

enter image description here

I'm afraid I didn't try to change layout (yet), but that will be another question...

8
  • I'm sorry, I missed @torbjorn-t 's comment... makes my answer a duplicate. I'll let it be for sake of the MWE?
    – long tom
    Oct 26, 2012 at 21:26
  • If you can, please write a code which out put like my picture. Oct 27, 2012 at 1:34
  • 2
    @minthao_2011 polynom can't create output exactly like your picture. It has three ways of representing polynomial division, examples of which you can see in polydemo.pdf, that I linked to in my comment to your question. Oct 27, 2012 at 8:15
  • 2
    @TomDierckx I took the liberty of expanding your example a little, and adding an image, hope that's OK. Oct 27, 2012 at 8:22
  • 1
    Style D in polynom package is what you need. \polylongdiv[style=D]{6x^3-2x^2+x+3}{x^2-x+1}
    – mac
    Feb 24, 2018 at 23:20
28

Since the structure lends itself to an array, here is such an elementary implementation:

enter image description here

\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}
0
8

For fun with TikZ.

Explanation: \phantom is used to vertically align x, x^2, x^3, etc.

enter image description here

\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}
3
  • 2
    Nice solution, hard to reuse without minimim explanations (eq , node{$6x^3-2x^2+\phantom{6}x+3$} and ++(-90:1) node{$6x^3-6x^2+6x\phantom{{}+3}$}.
    – pzorba75
    Aug 15, 2019 at 3:31
  • 1
    @pzorba75 I added some explanation of \phantom. Just tell me if you need more explain
    – Black Mild
    Aug 15, 2019 at 4:13
  • It is OK to me now, just a bit long to enter but the division looks rigth.
    – pzorba75
    Aug 15, 2019 at 12:59
4

This is an old question. Now, you can use tabularray

\documentclass[border=2mm]{standalone}
\usepackage{tabularray}
\usepackage{ninecolors}
\begin{document}
    \begin{tblr}{
            colspec={rrrrrrrr|rrrrr},
            cells={mode=dmath},
            colsep = .5mm } 
        \SetCell[r=2]{fg=red}- 
        & 6x^3 & - & 2x^2 & + & x & + & 3 & x^2 & - & x & + & 1 \\
\SetHline{9-13}{blue,0.5pt}
& 6x^3 & - & 6x^2 & + & 6x &  &  &  &  & 6x & + & 4 \\
\SetHline{2-8}{blue,0.5pt}
        %or \cline{2-8}
        \SetCell[r=2,c=3]{fg=red}-
&  &  & 4x^2 & - & 5x & + & 3 &  &  &  &  &  \\
&  &  & 4x^2 & - & 4x & + & 4 &  &  &  &  &  \\
        \SetHline{4-8}{blue,0.5pt}
        %\cline{4-8}
        &  &  &  & - & x & - & 1 &  &  &  &  &  \\
    \end{tblr}  
\end{document}

enter image description here

You must log in to answer this question.

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