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}
```

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}
```

## Best Answer

Changing the internal macros that are responsible for omitting zero terms you get what you want (but you have to specify the zero term in the input):