I have a table in a document in which I am not sure what the final font size is going to be. The font size will probably be 10, 11 or 12. The tables are fine at font size 10, but at 11 or 12 one or more of them is too wide.
I would like to have code in the table that will downsize the table slightly only if it is too wide, i.e.: only if it is wider than the column width. If the table already fits into the column then it should be left alone.
Is it possible to do this without writing a lot of complicated code. An MWE that illustrates this issue is given below. When the font size becomes 12, I want the table to adjust downwards to the column width:
\documentclass[10pt]{article}
\usepackage{graphics}
\usepackage[a4paper, left=50mm, right=50mm, top=50mm, bottom=50mm]{geometry}
\usepackage{caption}
\captionsetup[table]{skip=2pt}
\begin{document}
\begin{table}[H]
\centering
\caption{Elapsed Time (Seconds)}
%\resizebox{\columnwidth}{!}{%
\begin{tabular}{@{\vrule height 10.5pt depth4pt width0pt}llllllll}
& \multicolumn7c{Problem Size} \\
\cline{2-8}
Method & 2 & 10 & 90 & 250 & 900 & 2000 & 5000\\
\hline
Connoisseur & 0.5 & 3 & 21 & 49 & 120 & 323 & 600\\
Cowboy & 2 & 7 & 56 & 122 & 345 & 678 & 1545\\
Explorer & 0.5 & 2 & 19 & 45 & Crashed & Crashed & Crashed\\
Handyman & 6 & 31 & 258 & 600 & Crashed & Crashed & Crashed\\
\end{tabular} \\
\label{tab:elapsed}
\end{table}
\end{document}
As you may note, I tried \resizebox
, but that increases the table width when it is narrower than the column width.
Thank you.