# Array Long Division Vertical Alignment

I used code found here to create my own long division of a generalized polynomial.

As you can see, there is some vertical alignment problem when subscripts and superscripts are combined. My code is listed below. Could anyone lend a hand?

\documentclass{article}
\usepackage{amssymb}
\usepackage{array}

\newcommand{\x}[1]{\multicolumn{1}{|r}{#1}}

\begin{document}

$\renewcommand\arraystretch{1.2}% specify the vertical stretch \begin{array}{*{5}{>{\hfill}m{8.5mm}}}%specify the column width & & 1& 1& 0\\\cline{2-5} x \,- \, u& \x{f_{n-1}x^{n-1}}& f_{n-2}& {f_{n-3}x^{n-3}}& 1\\ & a& -1& & \\\cline{2-4} & & 1& -1& \\ & & 1& -1& \\\cline{3-5} & & & & 1\\ \end{array}$
\end{document}

• eek put those -1 into math mode:-) (but they woul dbe in math mode automatically had you not forced the column widths with m but why do that rather than leave the columns natural width? – David Carlisle Oct 8 '15 at 12:43
• Please always make your examples complete documents that show the problem. I tried adding \documentclass etc to this but got ! Undefined control sequence. l.15 \x You could edit the example to make it a full error-free document. – David Carlisle Oct 8 '15 at 12:46
• I mean, I linked the code I copied from... but I'm not very familiar with arrays, so I have no idea whether or not fixed width is better. In the link I included at the top of my post, I believe it's because that's what OP requested. – user879559 Oct 8 '15 at 12:51
• A search of the site will reveal a lot of questions (and answers) regarding long division. – Steven B. Segletes Oct 8 '15 at 13:12

You don't want fixed width columns here, and definitely not m. Also all the entries should be in math mode (the -1 with a hyphen rather than a minus sign was too painful:-)

Something like

\documentclass{article}
\usepackage{array}

\begin{document}

$\renewcommand\arraystretch{1.2}% specify the vertical stretch \setlength\extrarowheight{2pt} % \begin{array}{*{5}{r}}%Don'tspecify the column width & & 1& 1& 0\\\cline{2-5} \multicolumn{1}{r|}{x - u}& f_{n-1}x^{n-1}& f_{n-2}& f_{n-3}x^{n-3}& 1\\ & a& -1& & \\\cline{2-4} & & 1& -1& \\ & & 1& -1& \\\cline{3-5} & & & & 1\\ \end{array}$

\end{document}

• your minus signs have binary, not unary, spacing. and it would really look better if the 1s lined up nicely. (you'll have to earn your +1.) – barbara beeton Oct 8 '15 at 14:18
• @barbarabeeton hmm that's what the >{{}} was for I thought it was a polynomial expression with alignment points but I see now that the OP has omited the +/- so the body is really a list of terms not written as a polynomial so the >{{}} is not appropriate I'll remove in a bit... – David Carlisle Oct 8 '15 at 14:45
• @barbarabeeton betterer than it were? – David Carlisle Oct 8 '15 at 14:50
• oh, lots betterer! i like it now. (recognized by deserved upvote.) see -- that's why i'm the editor; i notice the discrepancies. – barbara beeton Oct 8 '15 at 16:34