# Is there a way to slightly shrink a table, including font size, to fit within the column boundaries?

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}{}
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}

-
Why not just use \small or \footnotesize at the beginning of table environment? Box scaling also has disadvantage, tabular line will be slightly scaled. –  Leo Liu Feb 11 '11 at 18:07
it make more sense to scale it exactly to linewidth, which is the same as using the best font size! –  Herbert Feb 11 '11 at 18:25
@Herbert, it is not quite the same as using the best font size, due to optical scaling of the fonts. Ie, cmr10 at 90% scale is not the same as cmr9. Also, as Leo says, the weight of the tabular lines will not be completely consistent. –  Lev Bishop Feb 12 '11 at 1:08
I just tried \small after \begin{table}, and although it does the job, I like the output that \resizebox gives better. –  Nathan Farrington Feb 12 '11 at 3:30
@Lev: as I said, scaling is better than using a too small font size. And the line width will also be scaled down so that they are still proportional to the font. –  Herbert Feb 12 '11 at 5:26

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}{}
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.

-
I have changed the question (and my paper) to use the \centering macro, thanks. –  Nathan Farrington Feb 12 '11 at 3:16
This worked the best for me. Using either \columnwidth or \linewidth seemed to give exactly the same results. –  Nathan Farrington Feb 12 '11 at 3:29
@Nathan: Please note that \columnwidth should always be the width of the column. The \linewidth is the width of the text lines and is different depending if you are in single of double column mode. –  Martin Scharrer Feb 12 '11 at 9:19
@Martin: that is not correct. They have both the same value, \textwidth is the width of the onecolumn part –  Herbert Feb 12 '11 at 13:23
@Martin: \columnwidth is correct for twocolumn mode, but \linewidth is the width of the current line, which can be smaller than \columnwidth, eg in a quotation environment in twocolumn mode which sets its own margins. –  Herbert Feb 12 '11 at 14:41

you can resize it to exactly the linewidth:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\noindent\hrulefill

\smallskip\noindent
\resizebox{\linewidth}{!}{%
\begin{tabular}{r|lll}
\multicolumn{1}{r}{}
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{document}

-

You can scale the whole table using \scalebox from the graphicx package.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{table}
\begin{center}
\scalebox{0.9}{
\begin{tabular}{r|lll}
\multicolumn{1}{r}{}
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{center}
\end{table}
\end{document}

-
I used \scalebox for years until I figured out that there is \resizebox! :-) You miss a % behind it. –  Martin Scharrer Feb 11 '11 at 18:00
@Martin I always tend to use scalebox, find it easier to use. –  Yiannis Lazarides Feb 11 '11 at 18:32
I have now tried both \scalebox and \resizebox, and I like \resizebox better because it seems to give a better end result. –  Nathan Farrington Feb 12 '11 at 3:27