180

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}
7
  • 7
    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, 2011 at 18:07
  • 2
    it make more sense to scale it exactly to linewidth, which is the same as using the best font size!
    – user2478
    Feb 11, 2011 at 18:25
  • 3
    @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, 2011 at 1:08
  • 1
    I just tried \small after \begin{table}, and although it does the job, I like the output that \resizebox gives better. Feb 12, 2011 at 3:30
  • 1
    @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.
    – user2478
    Feb 12, 2011 at 5:26

5 Answers 5

262

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}
8
  • 1
    I have changed the question (and my paper) to use the \centering macro, thanks. Feb 12, 2011 at 3:16
  • This worked the best for me. Using either \columnwidth or \linewidth seemed to give exactly the same results. Feb 12, 2011 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. Feb 12, 2011 at 9:19
  • @Martin: that is not correct. They have both the same value, \textwidth is the width of the onecolumn part
    – user2478
    Feb 12, 2011 at 13:23
  • 3
    @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.
    – user2478
    Feb 12, 2011 at 14:41
81

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}
3
  • 4
    I used \scalebox for years until I figured out that there is \resizebox! :-) You miss a % behind it. Feb 11, 2011 at 18:00
  • 1
    I have now tried both \scalebox and \resizebox, and I like \resizebox better because it seems to give a better end result. Feb 12, 2011 at 3:27
  • @MartinScharrer: Why do you say that? I don't understand that comment.
    – Jo Mo
    Feb 18, 2021 at 15:57
36

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}
1
  • the \noindent is really neat when equation numbering are in the picture!
    – davyjones
    May 13, 2017 at 10:02
6

If the tabular only needs to scaled down very little, it might be worth trying out the widetable package which is like a tabular* but does not need \extracolsep and works by calculating the right value for \tabcolsep, i.e, stretching or shrinking the intercolumn space on either side of a vertical line (if the table has them). This way the fontsize will stay the same which may be an advantage. But of course the maximum shrink is to zero (and that is seldom a workable idea) so it only works if the amount is needed small and the table has many columns.

1

This is a visual comparison to show that just scale too wide tables (right column) is always the wrong approach. The solution should be reducing the font size, and the column separations if needed, and in case it is necessary also to fit the width of the table exactly, use tabular* environment or packages as tabularx, tabulary or widetable (left column), and nothing is enough, redesign the table (not showed).

mwe

Do you see the problems at the right? Let me explain:

  1. The rules are also scaled, giving inconsistent thin rules (ugly, right?).

  2. The text of normal size scaled down do not look like small fonts (obtained with \small, \footnotesize, \scriptize or \tiny). It is less readable.

  3. Worse, every scaled table will have a different font size: 40 tables = 40 font sizes, not 2 or 3 standard sizes through the whole document (very ugly, right?).

  4. Worse, as you can scale down infinitely the table, the risk of allowing ridiculously unreadable small fonts sizes is high. Maybe you have noticed the that the last header if the left-bottom table have the wrong number, but... have you noticed that there are also four badly numbered cells in last table of the right column?

With the other approach, you decide the limit (note: the mine is \footnotesize) or if you lack common sense you cannot low to absurd limits. It is important to have that limit, because it will tell you when you have to pass plan B (redesign the table).

The code:

\documentclass[twocolumn,a5paper]{article}
\usepackage{lipsum,parskip,booktabs,graphicx,tabulary,tabularx}
\usepackage[margin=1cm,bmargin=7cm]{geometry}
\begin{document}

 \lipsum[1][1-3]    

\begin{tabularx}{\linewidth}{lXX}\toprule
& Heading 1 & Heading 2\\\cmidrule{2-3}
Row 1 & Cell 1,1 & Cell 1,2 \\
Row 2 & Cell 2,1 & Cell 2,2 \\\bottomrule
\end{tabularx}

% \lipsum[2][1-3]   

{\small\tabcolsep5pt 
\begin{tabularx}{\linewidth}{@{}lXXX@{}}\toprule
& Heading 1 & Heading 2 & Heading 3 \\\cmidrule{2-4}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3 \\\bottomrule
\end{tabularx}}

{\scriptsize
\tabcolsep1.7pt 
\begin{tabularx}{\linewidth}{@{}lXXXX@{}}\toprule
& Heading 1 & Heading 2 & Heading 3 & Heading 4 \\\cmidrule{2-5}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 & Cell 1,4 \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3 & Cell 2,4 \\\bottomrule
\end{tabularx}}


{\tiny
\tabcolsep1.1pt 
\begin{tabularx}{\linewidth}{@{}lXXXXX@{}}\toprule
& Heading 1 & Heading 2 & Heading 3 & Heading 4 & Heading 5\\\cmidrule{2-6}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 & Cell 1,4 & Cell 1,5   \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3 & Cell 2,4 & Cell 2,5 \\\bottomrule
\end{tabularx}}


{\tiny\tabcolsep1pt
\begin{tabulary}{\linewidth}{@{}lCCCCCCC@{}}\toprule
& Heading 1 &  Heading 2 & Heading 3 &  Heading 4 &  Heading 5 & Heading 6\\\cmidrule{2-7}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 & Cell 1,4 & Cell 1,5  & Cell 1,5 \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3 & Cell 2,4 & Cell 2,5  & Cell 1,5 \\\bottomrule
\end{tabulary}}


{\tiny\tabcolsep1pt
\begin{tabulary}{\linewidth}{@{}lCCCCCCCC@{}}\toprule
& Heading 1 &  Heading 2 & Heading 3 &  Heading 4 &  Heading 5 & Heading 6 & Heading 6\\\cmidrule{2-8}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 & Cell 1,4 & Cell 1,5  & Cell 1,6  & Cell 1,7  \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3 & Cell 2,4 & Cell 2,5  & Cell 2,5  & Cell 2,7  \\\bottomrule
\end{tabulary}}

\lipsum[2][1]
\footnote{Footnote as reference of reasonable and standard small font.} 

    \newpage \lipsum[1][1-3]    


{\centering
\begin{tabular}{lll}\toprule
& Heading 1 & Heading 2\\\cmidrule{2-3}
Row 1 & Cell 1,1 & Cell 1,2 \\
Row 2 & Cell 2,1 & Cell 2,2 \\\bottomrule
\end{tabular}\par}

\resizebox{\linewidth}{!}{%
\begin{tabular}{llll}\toprule
& Heading 1
& Heading 2
& Heading 3 \\\cmidrule{2-4}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3 \\\bottomrule
\end{tabular}}

\resizebox{\linewidth}{!}{%
\begin{tabular}{lllll}\toprule
 & Heading 1 & Heading 2 & Heading 3 & Heading 4 \\\cmidrule{2-5}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 & Cell 1,4 \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3 & Cell 2,4 \\\bottomrule
\end{tabular}}

\resizebox{\linewidth}{!}{%
\begin{tabular}{llllll}\toprule
& Heading 1 & Heading 2 & Heading 3 & Heading 4 & Heading 5\\\cmidrule{2-6}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 & Cell 1,4 & Cell 1,5\\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3 & Cell 2,4 & Cell 2,5\\\bottomrule
\end{tabular}}

\resizebox{\linewidth}{!}{%
\begin{tabular}{lllllll}\toprule
 & Heading 1 & Heading 2 & Heading 3 & Heading 4 & Heading 5 & Heading 6\\\cmidrule{2-7}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 & Cell 1,4 & Cell 1,5  & Cell 1,5 \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3 & Cell 2,4 & Cell 2,5  & Cell 1,5 \\\bottomrule
\end{tabular}}

\resizebox{\linewidth}{!}{%
\begin{tabular}{llllllll}\toprule
 & Heading 1 & Heading 2 & Heading 3 & Heading 4 & Heading 5 & Heading 6 & Heading 7\\\cmidrule{2-8}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 & Cell 1,4 & Cell 1,5  & Cell 1,5  & Cell 1,5 \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3 & Cell 2,4 & Cell 2,5  & Cell 1,5 & Cell 1,5  \\\bottomrule
\end{tabular}}

\lipsum[2][1-2]
\
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.