# I need these two boxes to be the same length using tabular

The box on the left should mirror the box on the right. So A should look as if it's spanning 3 columns and 2 rows, etc. How can I fix the width of the table on the right using tabular? Code is below. Sorry in advance - I am very new at this.

\begin{center}
\begin{tabular}{|ccc|c|}
\hline
2 & 1 & 4 & 10 \\
0 & 5 & -1 & 6 \\
\hline
3 & 7 & -8 & 9 \\
\hline
\end{tabular}
=
\begin{tabular}{|ccc|c|}
\hline
&\multirow{2}{*}{$A$}&&\multirow{2}{*}{$\hat{b}$} \\
&&& \\ \hline
&$\bar{c}$&&$d$ \\ \hline
\end{tabular}
\end{center}

The width of each column in a tabular environment can be specified in the argument at the beginning of the environment. The letters l, c and r are used to declare left aligned, centered and right aligned columns respectively, but one can also use the letter p, which takes a length as an argument to specify the width of the column. With the array package, one can also use the similar commands m and b. The difference between p, m and b is the vertical alignment of the text; use p to align at the top of the cell, m in the middle and b at the bottom. See the LaTeX wikibook for a more detailed explanation. The answer here can also be useful, as it introduces a way to define horizontally centered columns with specified width.

Taking your example, the c arguments can be replaced by ms to give the following result.

\documentclass{article}
\usepackage{multicol, multirow, array}

\begin{document}

\begin{center}
\begin{tabular}{|m{2ex}m{2ex}m{2ex}|m{2ex}|}
\hline
2 & 1 & 4 & 10 \\
0 & 5 & -1 & 6 \\
\hline
3 & 7 & -8 & 9 \\
\hline
\end{tabular}
=
\begin{tabular}{|m{2ex}m{2ex}m{2ex}|m{2ex}|}
\hline
&\multirow{2}{*}{$A$}&&\multirow{2}{*}{$\hat{b}$} \\
&&& \\ \hline
&$\bar{c}$&&$d$ \\ \hline
\end{tabular}
\end{center}

\end{document}

• you are so amazing!!!!! thank you – Erika Olsen Dec 4 '19 at 16:41
• I am getting an "Undefined control sequence" error now when I add this code to my document. "Undefined control sequence. \adl@hline ...mpcnta \xdef \adl@rowsL {\adl@rowsL (#1/\number \@tempcnta );}... l.123 \hline" – Erika Olsen Dec 4 '19 at 20:27
• Did you load the multirow and the array packages? – Vincent Dec 4 '19 at 20:31
• I did! I was told erasing the aux file might help. When I put the code in a new tex file it works just fine – Erika Olsen Dec 6 '19 at 18:25

You can also measure the width and height. It will save some space, but obviously takes more effort.

Note that even a [b] tabular will still have a nonzero depth. Also, in the \parbox, the first [c] centers b, while the second [c] centers A. The \strut improves the centering.

\documentclass{article}
\usepackage{multicol, multirow}

\begin{document}

\begin{center}
\sbox0{\begin{tabular}{@{}ccc@{}}
2 & 1 & 4 \\
0 & 5 & -1 \\
3 & 7 & -8
\end{tabular}}% measure width \wd0
\sbox1{\begin{tabular}{@{}ccc@{}}
2 & 1 & 4 \\
0 & 5 & -1
\end{tabular}}% measure height \ht1 + \dp1
\begin{tabular}{|ccc|c|}
\hline
2 & 1 & 4 & 10 \\
0 & 5 & -1 & 6 \\
\hline
3 & 7 & -8 & 9 \\
\hline
\end{tabular}
=
\begin{tabular}{|c|c|}
\hline
\parbox[c][\dimexpr \ht1+\dp1][c]{\wd0}{\centering \strut $A$} & $\hat{b}$ \\
\hline
$\bar{c}$&$d$ \\
\hline
\end{tabular}
\end{center}

\end{document}
• thank you SO much!! – Erika Olsen Dec 4 '19 at 16:42
• I also get an error with this one. Undefined control sequence. – Erika Olsen Dec 4 '19 at 20:28
• I get no errors or warnings. Try erasing the aux file (clear project). – John Kormylo Dec 5 '19 at 0:18
• I don't get warning when I put it in a new tex file. I'm still getting the error even after erasing the aux file :( – Erika Olsen Dec 9 '19 at 17:40
• I actually fixed this by moving the {multicol, multirow} to the top of my list? weird! – Erika Olsen Dec 9 '19 at 18:31