I was trying to use the answer from here to ensure my tables fit to the width of my page. I'd like to redefine the tabular environment so that this change is applied automatically if the table's width exceeds the page width. Is there any way to do this?
1 Answers
Just for fun:
\documentclass{article}
\usepackage{graphicx}
\usepackage{environ}
\usepackage{showframe}% alignment tool
\NewEnviron{tabscale}{\bgroup% local changes
\normalsize
\sbox9{\BODY}%
\ifdim\wd9<\textwidth
\usebox9
\else
%\usebox9
\small
\tabcolsep=0.86\tabcolsep
\sbox9{\BODY}%
\ifdim\wd9<\textwidth
\usebox9
\else
%\usebox9
\footnotesize
\tabcolsep=0.86\tabcolsep
\sbox9{\BODY}%
\ifdim\wd9<\textwidth
\usebox9
\else
%\usebox9
\scriptsize
\tabcolsep=0.86\tabcolsep
\sbox9{\BODY}%
\ifdim\wd9<\textwidth
\usebox9
\else
%\usebox9
\tiny
\tabcolsep=0.86\tabcolsep
\sbox9{\BODY}%
\ifdim\wd9<\textwidth
\usebox9
\else
\resizebox{\textwidth}{!}{\BODY}% by this point you are illegible anyway
\fi
\fi
\fi
\fi
\fi
\egroup}
\begin{document}
\begin{table}
\centering
\begin{tabscale}
\begin{tabular}{cccccccccccc}
The & quick & red & fox & jumped & over & the & lazy & brown & dog & and & grinned
\end{tabular}
\end{tabscale}
\end{table}
\end{document}
- 79,712
- 3
- 50
- 120
-
Thank you for this. I really appreciate you taking the time to do this. It seems like the concept of what I am trying to do is not recommended. – user41177 Sep 14 '23 at 19:49
-
There are other ways to make tabulars smaller. And I won't be offenced if tyou throw out all the steps except the first and last. I just thought it would be cute to throw them all into one environ. – John Kormylo Sep 14 '23 at 20:16
\textwidth). – Zarko Sep 13 '23 at 05:30\resizeboxwith tables" comment below the answer you've provided a link to? If you did, did you pause and ponder whether you should heed this admonition? – Mico Sep 13 '23 at 05:42\resizeboxon tables. – David Carlisle Sep 13 '23 at 06:02