# How may I arrange the following product of two polynomials accordingly?

(1). A proper arrangement is required because some of the terms are scattered.

(2). This is how the aforementioned arrangement must look.

    \documentclass[11pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{booktabs}
\newcommand*{\Ph}{\hphantom{)}}%

\begin{document}
$\begin{array}{r@{} r@{} r@{} r@{} r r} x^3 &{}+2x^{2} &{}+2x &{}+1 \\ \times (x^2 &{}-x &{}+1) &\\ \cmidrule{1-4} x^{5} & +2x^{4} &{} +2x^{3} &{} +x^{2}\\ & -1x^{4} &{} -2x^{3} &{} -2x^{2} -1x\\ && +1x^{3} &{} +2x^{2} &{} +2x &{} +1 \\ \cmidrule{1-6} x^{5} &{}+ x^{4} &{}+ x^{3} &{}+ x^{2} &{}+ x &{}+ 1 \end{array}$
\end{document}


Something like this, maybe?

\documentclass[11pt,a4paper]{article}
\usepackage{array,booktabs}

\begin{document}
$\begin{array}{@{} r *{12}{ @{}>{{}}r<{{}} } @{}} & x^3 & + & 2x^2 & + & 2x^{\phantom{2}} & + & 1\phantom{x^2} \\ \times \\ & x^2 & - & x^{\phantom{2}} & + & 1\phantom{x^2} \\ \midrule & x^5 & + & 2x^4 & + & 2x^3 & + & x^2\\ & & - & x^4 & - & 2x^3 & - & 2x^2 & - & x\\ & & & & + & x^3 & + & 2x^2 & + & 2x & + & 1\\ \midrule & x^5 & + & x^4 & + & x^3 & + & x^2 & + & x & + & 1\\ \end{array}$
\end{document}

• Absolutely brilliant! I was struggling to find a solution since last weekend. Thank you so very much! It means a lot! – Nisal Kevin Kotinkaduwa Mar 2 '15 at 18:40