5

I am quite new to TeX, so i don't know how to represent polynom division in latex. I can't use package polynom, since I don't have a polynom with numbers so this is a generic solution for this fraction (x_1^n-x_0^n)/(x_1-x_0)

I would appreciate some help to represent this somehow like this:

enter image description here

A similar question was answered there: How to draw polynom division? but i want to picture polynom division in more convinient style

enter image description here

like the package polynom does it and don't know how to tune that solution for my purposes

Danny Lo
  • 153

1 Answers1

6

This is using the under-development tabstackengine package, first introduced here at Writing a table with equally spaced columns, based on the widest column (source code available at Measuring align).

The package extends the stackengine package by adding tabbing capability. This answer, Can I tab inside of align environment?, gives some of the syntax of the package. I apologize that I have been lax in completing the package and getting it out the door, so the only way to see it in action is by searching this site for tabstackengine.

In this particular answer, I set up the polynomial division with a tabular stack, where I set the alignments of each column. The only twist is the introduction of the macro \rl{} which give a rule corresponding to the typeset contents of the mathematical argument (extended with a llap and \rlap to make smooth transitions).

The answer below has been EDITED in response to Barbara'a comment, through a redefinition of \rl{}. My earlier solution artificially extended the horizontal gap between stacked columns, which was a proper criticism. An additional criticism levied had to do with the unequal spacings around the math operators. To a large extent, this edit corrects much of that. However, residual asymmetries about the - and + characters are notably due to the alignment requirements of the columns. For example, in the middle rows, there is more space prior to the 7x than after the preceding -x^2. This occurs because the 7x must achieve right-alignment with the somewhat wider (4x three rows later. In essence, mathrel spacings are sacrificed in order to maintain column alignments, which is considered essential to this problem.

\documentclass{article}
\usepackage{fixltx2e}
\usepackage{tabstackengine}
\stackMath
\newsavebox\tempbox
\newlength\templen
\def\rl#1{%
  \sbox\tempbox{$#1$}%
  \setlength\templen{\wd\tempbox}%
  \llap{\rule{1.5pt}{.1ex}}\rule{\templen}{.1ex}\rlap{\rule{1.5pt}{.1ex}}}
\setstacktabulargap{0pt}
\begin{document}
\tabularShortstack{crcrcrcrl}{
 &(3x^3&-&10x^2&+&7x &-&12&): (x-3) = 3x^2 -x + 4\\
-&(3x^3&-&9x^2 &)&   & &  &\\
\rl{-}&\rl{(3x^3}&\rl{-}&\rl{-(x^2}&\rl{+}&&&&\\
 &     & &-x^2 &+&7x & &  &\\
 &     &-&(-x^2&+&3x &)&  &\\
&&\rl{-}&\rl{-(x^2}&\rl{+}&\rl{(7x}&\rl{-}&&\\
 &     &&      & &4x &-&12&\\
 &     &&      &-&(4x&-&12&)\\
&&&&\rl{+}&\rl{(7x}&\rl{-}&\rl{12}&\rl{)}\\
 &&&&&&&0&
}
\end{document}

enter image description here

Here is an example of another problem cited by the OP. The only differences here were the need to use \rlap if an entry was to be allowed to cross column boundaries, and I also changed the column alignment to l for the polynomial entries, as opposed to r in the last example, which had constant coefficients.

\documentclass{article}
\usepackage{fixltx2e}
\usepackage{tabstackengine}
\stackMath
\newsavebox\tempbox
\newlength\templen
\def\rl#1{%
  \sbox\tempbox{$#1$}%
  \setlength\templen{\wd\tempbox}%
  \llap{\rule{2.1pt}{.1ex}}\rule{\templen}{.1ex}\rlap{\rule{2.1pt}{.1ex}}}
\setstacktabulargap{0pt}
\begin{document}
\tabularShortstack{crllclcl}{
 &(x^n&-&x_0^n&)%
  \rlap{$:(x-x_0) =  x^{n+1} + x_0x^{n-2} + x_0^2x^{n-3} + \ldots $}&&&\\
-&(x^n&-&x_0x^{n-1} &)&   & &\\
\rl{-}&\rl{(x^n}&\rl{-(}&\rl{(x_0x^{n-1}}&\rl{+}&&&\\
 &     & &x_0x^{n-1} &-&x_0^n & &\\
 &     &-(&x_0x^{n-1}&-&x_0^2x^{n-2} &)&\\
&&\rl{-(}&\rl{(x_0x^{n-1}}&\rl{+}&\rl{x_0^2x^{n-2}}&\rl{-}&\\
 &     &&      & &x_0^2x^{n-2}&-&x_0^n\\
\rule{0ex}{3ex}&&&&&\rlap{...................}&&
}
\end{document}

enter image description here

  • there-s really too much space after many of the minus signs. both operations and unary minus signs are affected. – barbara beeton Jan 23 '14 at 16:50
  • @barbarabeeton Please see edited answer. – Steven B. Segletes Jan 23 '14 at 18:23
  • Thanks for answering my question! I wonder though if I can put that minus sign between the lines? – Danny Lo Jan 23 '14 at 18:28
  • @DanyloEsterman You are most welcome. What do you mean "between the lines"? Do you mean to shift the leading minus vertically, horizontally, or something completely different? – Steven B. Segletes Jan 23 '14 at 18:30
  • better. not perfect, but i expect the extra space between minus/plus signs and a following element is an accommodation to line up with later lines that have parentheses in those locations. still, the initial minus signs pre-parentheses should really be spaced as unary, not binary; that would compensate somewhat for the extra space inserted on account of the open parentheses. (this is rather a tricky situation, and you may have already made the best of it.) – barbara beeton Jan 23 '14 at 18:44
  • This is what i mean: http://imagizer.imageshack.us/v2/800x600q90/546/gdbd.png – Danny Lo Jan 23 '14 at 18:49
  • And actually the second image was only to show the style of the drawing, what i really need to draw is on the first image (x_1^n-x_0^n)/(x_1-x_0) Trying to apply your code to my formula, but i dont really know how to deal with all these ampersands – Danny Lo Jan 23 '14 at 18:50
  • @DanyloEsterman The ampersands are the column delimiters. Each row should have the same number of ampersands (8), meaning a total of 9 columns (with the alignments given by (crcrcrcrl). For the \rl{} lines, I place the widest element of the column as the argument, if I want an underline in that column. By the way, I was unable to look at the imagizer site, because it is blocked from me. But if I get a chance, i will try to look at your top example. – Steven B. Segletes Jan 23 '14 at 20:07
  • I still cannot reach desired result. Could you post code for drawing this polynom divison http://i.stack.imgur.com/RlyJv.png please? – Danny Lo Jan 29 '14 at 14:59
  • @DanyloEsterman The .tex code I use is given in the above answer. The version of tabstackengine I use to create the above result is given at the end of the answer: http://tex.stackexchange.com/questions/142406/measuring-align/142608#142608. It is the piece of code that begins with the line \def\tabstackengineversionnumber{V0.21}. The only other suggestion I might have is to make sure your other packages are up to date. Packages referenced directly or indirectly include stackengine, fixltx2e, etoolbox, etex, and calc. – Steven B. Segletes Jan 29 '14 at 15:32
  • I've already got tabstackengine working, but I still can't figure it out how to draw the right polynom division. The .tex code you given above is for another problem, namely this one: http://i.stack.imgur.com/bQwaV.jpg As I already mentioned, I provided this polynom division just to make you understand how the result has too look. – Danny Lo Jan 29 '14 at 16:19
  • Sorry if i express myself not clearly enough, english is not my mother tognue. – Danny Lo Jan 29 '14 at 16:28
  • @DanyloEsterman Your English is quite acceptable. I had forgotten that you had asked further assistance on the other type of problem. See revised answer to see if it helps. – Steven B. Segletes Jan 29 '14 at 16:50