# Multiplication Formatting

Thanks for stopping by and looking at my question.

I'm trying to format my homework like my professor has shown in his notes, but I don't know how to write the code to make it look like this (shown below).

Any help you might be able to provide would be much appreciated.

Here's another array-based solution. The array features a total of 9 columns: 5 columns for the powers of x and 4 columns for the + and - symbols, which are thus vertically aligned with each other.

An \rlap instruction is used to make the final . (period) and the QED-symbol protrude beyond the right-hand edge of the array.

\documentclass{article}
\usepackage{array}   % for "\newcolumntype" macro
\usepackage{booktabs}% for "\midrule" macro
\usepackage{amsthm}  % for "\qedsymbol" macro
\newcolumntype{C}{>{{}}c<{{}}}
\newcommand{\ltimes}{\multicolumn{1}{l}{\times}}
\begin{document}
$\setlength\arraycolsep{0pt} \renewcommand\arraystretch{1.5} \begin{array}{*{4}{rC}r} & & & - & 3x^2 & + & 2x & - & 4 \\ & &\ltimes& & 5x^2 & & & + & 3 \\ \midrule & & & - & 9x^2 & + & 6x & - & 12\\ -15x^4 & + & 10x^3 & - & 20x^2 \\ \midrule -15x^4 & + & 10x^3 & - & 29x^2 & + & 6x & - & 12\rlap{.\quad\qedsymbol}\\ \end{array}$
\end{document}

• Thank you, @Mico, I appreciate your time, your solution looks very nice! Nov 17 '16 at 21:09

It looks like he used array, which is more or less the same as tabular but in math mode. I would prefer it without all the spaces.

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{displaymath}
\begin{array}{*{5}{@{}r@{}}}
&  & -3x^2 & {}+2x & {}-4\\
& \times & 5x^2 & & {}+3\\\midrule
& & -9x^2 & {}+6x & {}-12\\
-15x^4 & {}+10x^3 & {}-20x^2\\\midrule
-15x^4 & {}+10x^3 & {}-29x^2 & {}+6x & {}-12
\end{array}
\end{displaymath}
\end{document}


• Thanks, @StefanH, that looks great! Yeah, I'm not sure why all the space in his, but yours looks good to me! :) Nov 17 '16 at 20:54
• In rows 1 and 2, the final - and + symbols are out of alignment with the - symbols in rows 3 and 5, even though they're all binary operators. Is this intentional?
– Mico
Nov 17 '16 at 20:57
• Thanks, @Mico, I didn't even notice the - and + being out of alignment. Nov 17 '16 at 21:05
• @Mico The signs are not aligned. I have the whole term, including the sign, in one column. Then I preferred to align the x. To do this a bit better the signs should have their own columns. Nov 17 '16 at 21:15

I propose another solution, based on alignedat:

\documentclass{article}
\usepackage{booktabs}
\usepackage{mathtools}

\begin{document}

\begin{array}{@{}c@{}} \begin{alignedat}{5} & & & & -3&x^2 & {}+2&x & {}-4& \\ & & & &{}\times 5&x^2 & & & {}+3 & \\\midrule[0.4pt] & & & & -9 & x^2 & {}+6 &x & {}-12& \\ -15 & x^4 & {}+10 & x^3 &{}-20 & x^2\\\midrule[0.4pt] -15 & x^4 & {}+10 & x^3 & {}-29&x^2 & {}+6 &x & {}-12& \end{alignedat} \end{array}

\end{document}


• Hello, @Bernard! The more ways the better, I appreciate you taking the time to answer! :) Nov 17 '16 at 21:15

With autoaligne and the help of a trick in https://tex.stackexchange.com/a/339525/4427

\documentclass{article}
\usepackage{autoaligne}

%% A trick for an empty delimiter
\newcommand{\makeempty}[1]{%
\begingroup\lccode~=#1 \lowercase{\endgroup\def~}{\mathbin{\phantom{+}}}%
\mathcode#1="8000
}

\begin{document}

\setlength{\medmuskip}{18mu} \makeempty{V} \definirseparateurs{\\}{+||-||V}{} \autoaligne{ +- 3x^2 + 2x - 4 \\ V \times\hfill V 5x^2 ++ 3 \\ \noalign{\vspace{3pt}\hrule\vspace{3pt}} +- 9x^2 + 6x - 12 \\ \-15x^4 + 10x^3 - 20x^2 \\ \noalign{\vspace{3pt}\hrule\vspace{3pt}} \-15x^4 + 10x^3 - 29x^2 + 6x - 12 }

\end{document}


If you want it more compact, remove the \setlength line:

Here's a more accurate rendering of the original.

\documentclass{article}
\usepackage{amsthm,array}

\begin{document}

$\setlength{\extrarowheight}{1ex} \begin{array}{@{}rclcrcrclll} &&& - & 3x^2 & + & 2x & - & 4 \\[1ex] && \times & & 5x^2 &&& + & 3 \\[1ex] \cline{1-10} &&& - & 9x^2 & + & 6x & - & 12 \\[1ex] -15x^4 & + & 10x^3 & - & 20x^2 \\[1ex] \cline{1-10} -15x^4 & + & 10x^3 & - & 29x^2 & + & 6x & - & 12 && \qedsymbol \end{array}$
\end{document}


• Ah, so that's how my professor go all that space in there! I didn't think I liked it originally, but now it's growing on me. Thanks, @egreg! Nov 17 '16 at 21:40
• @jbrow35 I don't think autoaligne was used, it's quite a new package. I suspect an array` similar to Mico's. Nov 17 '16 at 21:42
• Oh, okay. Yeah, I think he wrote these notes back in 2013. Nov 17 '16 at 21:43
• @jbrow35 I added a possible way your professor used. Nov 17 '16 at 22:02