0

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. What it currently looks like

\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} 
Erika Olsen
  • 197
  • 1
  • 8

2 Answers2

3

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}

enter image description here

Vincent
  • 20,157
1

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}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120