# Addition and Multiplication Tables

I am trying to create addition and multiplication tables for certain bases, but I want to construct them in a way different than most addition/multiplication tables are made, where the line divisions occur all throughout the table. I am trying to replicate exactly this (but to be able to extend it to whatever size array I want):

I see the following can produce one table easily:

\begin{center}
\begin{tabular}{ c| c | c | c | c |}
+ & 0 & 1 & 2 & 3 \\
\hline
0 & 0 & 1 & 2 & 3 \\
\hline
1 & 1 & 2 & 3 & 10 \\
\hline
2 & 2 & 3 & 10 & 11 \\
\hline
3 & 3 & 10 & 11 & 12 \\
\hline
\end{tabular}
\end{center}


How might I actually make the spacing uniform though (the numbers appear to be "lifted" a bit and not in the center of their respective boxes)? Also, how might I increase the spacing within each box?

• what problem are you having here? These are just tables. Please show some minimal code and point to the very problem you are having. What have you tried so far? Commented Nov 5, 2014 at 15:01
• Do you want latex to fill in the tables automatically? If not, what exactly is the question as otherwise there doesn't seem to be anything special in those tables, the simplest use of array would make them? Commented Nov 5, 2014 at 15:02
• The easiest way would be to use a Tikz matrix. Commented Nov 5, 2014 at 20:36
• You might also want to check the math...3+3 is not 12 and 3x3 is not 21. Commented May 21 at 15:20

Starting from your table, I'd use a decimal alignment column rather than c to ensure columns are equal width and o make the numbers line up correctly, and perhaps use thicker rules for the first row and column:

\documentclass{article}

\usepackage{dcolumn}
\newcolumntype{2}{D{.}{}{2.0}}
\begin{document}

\begin{center}
\renewcommand\arraystretch{1.3}
\setlength\doublerulesep{0pt}
\begin{tabular}{r||*{4}{2|}}
+ & 0 & 1 & 2 & 3 \\
\hline\hline
0 & 0 & 1 & 2 & 3 \\
\hline
1 & 1 & 2 & 3 & 10 \\
\hline
2 & 2 & 3 & 10 & 11 \\
\hline
3 & 3 & 10 & 11 & 12 \\
\hline
\end{tabular}
\end{center}

\end{document}


Let TeX do the computations! However, the maximum allowable base is 36.

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{array}
\usepackage{xparse}

\newcolumntype{O}{>{\centering\arraybackslash}p{1.5em}}

\ExplSyntaxOn
{% #1 is the base
\induktio_make_table:nnn { #1 } { + } { $+$ }
}
\NewDocumentCommand{\multiplicationtable}{m}
{% #1 is the base
\induktio_make_table:nnn { #1 } { * } { $\times$ }
}

\tl_new:N \l__induktio_table_body_tl
\int_new:N \l__induktio_row_number_int

\cs_new_protected:Npn \induktio_make_table:nnn #1 #2 #3
{
\int_zero:N \l__induktio_row_number_int
% add the operation symbol
\tl_set:Nn \l__induktio_table_body_tl { #3 }
% add the first row
\int_step_inline:nnnn { 0 } { 1 } { #1-1 }
{ \tl_put_right:Nx \l__induktio_table_body_tl { & \int_to_Base:nn { ##1 } { #1 } } }
\tl_put_right:Nn \l__induktio_table_body_tl { \\ \hline }
% add the subsequent rows
\int_step_inline:nnnn { 0 } { 1 } { #1-1 }
{
% first column
\tl_put_right:Nx \l__induktio_table_body_tl { \int_to_Base:nn { ##1 } { #1 } }
% subsequent columns
\int_step_inline:nnnn { 0 } { 1 } { #1-1 }
{
\tl_put_right:Nx \l__induktio_table_body_tl
{
& \int_to_Base:nn { ####1 #2 \l__induktio_row_number_int } { #1 }
}
}
\tl_put_right:Nn \l__induktio_table_body_tl { \\ \hline }
\int_incr:N \l__induktio_row_number_int
}
% print the table
\begin{tabular}{c|*{#1}{O|}}
\tl_use:N \l__induktio_table_body_tl
\end{tabular}
}
\ExplSyntaxOff

\begin{document}

\noindent

\bigskip

\footnotesize

\noindent

\bigskip

\noindent
\multiplicationtable{16}

\end{document}


If you want heavy rules, we can use David's trick:

\cs_new_protected:Npn \induktio_make_table:nnn #1 #2 #3
{
\group_begin:
\dim_set:Nn \doublerulesep { 0pt }
\int_zero:N \l__induktio_row_number_int
% add the operation symbol
\tl_set:Nn \l__induktio_table_body_tl { #3 }
% add the first row
\int_step_inline:nnnn { 0 } { 1 } { #1-1 }
{ \tl_put_right:Nx \l__induktio_table_body_tl { & \int_to_Base:nn { ##1 } { #1 } } }
\tl_put_right:Nn \l__induktio_table_body_tl { \\ \hline\hline }% two rules here
% add the subsequent rows
\int_step_inline:nnnn { 0 } { 1 } { #1-1 }
{
% first column
\tl_put_right:Nx \l__induktio_table_body_tl { \int_to_Base:nn { ##1 } { #1 } }
% subsequent columns
\int_step_inline:nnnn { 0 } { 1 } { #1-1 }
{
\tl_put_right:Nx \l__induktio_table_body_tl
{
& \int_to_Base:nn { ####1 #2 \l__induktio_row_number_int } { #1 }
}
}
\tl_put_right:Nn \l__induktio_table_body_tl { \\ \hline }
\int_incr:N \l__induktio_row_number_int
}
% print the table
\begin{tabular}{c||*{#1}{O|}}% two rules here
\tl_use:N \l__induktio_table_body_tl
\end{tabular}
\group_end:
}


I'll show only the first two tables

Heavier rules can be obtained by using \hline\hline\hline and ||| or more of them.

The default is to center text in each node and align the centers. By drawing the lines separately one can leave the top and left blank.

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}
\matrix (m) [nodes={minimum width=2em,minimum height=2ex},matrix of nodes]
{
+&0&1&2&3\\
0&0&1&2&3\\
1&1&2&3&10\\
2&2&3&10&11\\
3&3&10&11&12\\
};
\draw[very thick] (m-1-1.north east) -- (m-5-1.south east);
\draw[very thick] (m-1-1.south west) -- (m-1-5.south east);
\foreach \x in {2,...,5}{
\draw (m-1-\x.north east) -- (m-5-\x.south east);
\draw (m-\x-1.south west) -- (m-\x-5.south east);
}
\end{tikzpicture}
\end{document}


If you would rather avoid using Tikz, one could create a cell with \makebox.

\documentclass[border=2mm]{standalone}

\newcommand{\cell}[1]% #1 = text
{\makebox[1em]{#1}}

\begin{document}
\begin{tabular}{ c| c | c | c | c |}
\cell{$+$} & \cell{0} & \cell{1} & \cell{2} & \cell{3} \\
\hline
\cell{0} & \cell{0} & \cell{1} & \cell{2} & \cell{3} \\
\hline
\cell{1} & \cell{1} & \cell{2} & \cell{3} & \cell{10} \\
\hline
\cell{2} & \cell{2} & \cell{3} & \cell{10} & \cell{11} \\
\hline
\cell{3} & \cell{3} & \cell{10} & \cell{11} & \cell{12} \\
\hline
\end{tabular}
\end{document}


• How is this easier than a tabular? Commented Nov 5, 2014 at 21:31
• Easier to control the cell size, obviously not easier to create. But that does give me another idea. Commented Nov 5, 2014 at 21:33
• @percussse - Thank you for tightening the code. Commented Nov 6, 2014 at 1:23