GeneralLong Multiplication

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
jlamber
Posts: 5
Joined: Mon Jul 27, 2009 5:32 pm

Long Multiplication

Post by jlamber »

I am trying to create a long multiplication (like here
http://mathworld.wolfram.com/LongMultiplication.html) and vertical form addition http://mathworld.wolfram.com/Addition.html but I don't know how to do this cleanly in Latex. I used \begin{array} but it doesn't looks very nice. Do you have any suggestions?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Long Multiplication

Post by gmedina »

Hi,

using tabular environments could be an option:

Code: Select all

\documentclass{article}
\usepackage{array}

% command that will typeset the carriage
% syntax: \mycarr{<value>} or \mycarr (default carriage=1)
\newcommand\mycarr[1][1]{\scriptstyle #1\rule{8pt}{0pt}}

\begin{document}

{\setlength\arrayrulewidth{.8pt}
\setlength\tabcolsep{4pt}
\begin{tabular}{*{5}{>{$}c<{$}}}
  && 3 & 8 & 4\\
  \times &&& 5 & 6 \\\hline
  & 2 & 3 & 0 & 4\\
  1 & 9 & 2 & 0 &\\\hline
  2 & 1 & 5 & 0 & 4
\end{tabular}}

\vspace{1cm}

{\setlength\arrayrulewidth{.8pt}
\setlength\tabcolsep{4pt}
\begin{tabular}{*{4}{>{$}c<{$}}>{$}l<{$}>{\bfseries}l}
  & \mycarr & \mycarr  && \leftarrow & carries\\[-4pt]
  & 1 & 5 & 8 & \leftarrow & adddend1\\
  + & 2 & 4 & 9 & \leftarrow & adddend2 \\\cline{1-4}
  & 4 & 0 & 7 & \leftarrow & sum\\
\end{tabular}}

\vspace{1cm}

{\setlength\arrayrulewidth{.8pt}
\setlength\tabcolsep{4pt}
\begin{tabular}{*{4}{>{$}c<{$}}>{$}l<{$}>{\bfseries}l}
  & \mycarr[2] & \mycarr[2]  & & \leftarrow & carries\\[-4pt]
  & 9 & 9 & 9 & \leftarrow & adddend1\\
  &  & 9 & 9 & \leftarrow & adddend2\\
  + &  & 9 & 9 & \leftarrow & adddend3 \\\cline{1-4}
  1 & 1 & 9 & 7 & \leftarrow & sum\\
\end{tabular}}

\end{document} 
Some features provided by the array package were used; please refer to the package documentation for further information.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply