[Tex/LaTex] way to slightly shrink a table, including font size, to fit within the column boundaries

scalingtables

I have a table that is just a little too wide for a 3.33" column. Is there a way to simply shrink the table a little to make it fit? I'm OK if the 10pt font becomes 9pt-something. Here is an example.

\begin{table}
\centering
\begin{tabular}{r|lll}
\multicolumn{1}{r}{}
& \multicolumn{1}{l}{Heading 1}
& \multicolumn{1}{l}{Heading 2}
& \multicolumn{1}{l}{Heading 3} \\ \cline{2-4}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3
\end{tabular}
\end{table}

Best Answer

You can resize it using \resizebox{<width>}{<height>} from the graphics package. The column width is \columnwidth and you can select ! for the height to make it scale along with the width.

\usepackage{graphics}
% ...

\begin{table}
\centering
\resizebox{\columnwidth}{!}{%
\begin{tabular}{r|lll}
\multicolumn{1}{r}{}
& \multicolumn{1}{l}{Heading 1}
& \multicolumn{1}{l}{Heading 2}
& \multicolumn{1}{l}{Heading 3} \\ \cline{2-4}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3
\end{tabular}%
}
\end{table}

Should the table include verbatim or similar material than \resizebox isn't good enough. You can use the {adjustbox}{width=\columnwidth} environment from the adjustbox package instead. It is based on the same graphicx code as \resizebox but allows for any content.

Please do not use the center environment in floats (figure, table), it generates an extra margin and doesn't always work. Use the \centering macro instead.


Solution with adjustbox:

\usepackage{adjustbox}
% ...
\begin{table}
\begin{adjustbox}{width=\columnwidth,center}
\begin{tabular}{r|lll}
\multicolumn{1}{r}{}
& \multicolumn{1}{l}{Heading 1}
& \multicolumn{1}{l}{Heading 2}
& \multicolumn{1}{l}{Heading 3} \\ \cline{2-4}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3
\end{tabular}
\end{adjustbox}
\end{table}