Is there a way to slightly shrink a table, including font size, to fit within the column boundaries?
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}
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}{}
& \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{center}
\end{table}
\end{document}
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}{}
& \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{document}