0

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?

7
  • 3
    I wouldn't do this. This lead to inconsistent font size of table texts. Rather redesign table that use prescribed width (=\textwidth).
    – Zarko
    Commented Sep 13, 2023 at 5:30
  • 3
    Just because a particular answer gets a lot of upvotes does not mean that its proposed solution method can or should be applied willy-nilly. Did you maybe notice the "Never use \resizebox with 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
    Commented Sep 13, 2023 at 5:42
  • 2
    Have you studied the posting My table doesn't fit; what are my options?
    – Mico
    Commented Sep 13, 2023 at 5:50
  • 4
    never use \resizebox on tables. Commented Sep 13, 2023 at 6:02
  • 3
    I just sacrificed 1 of my reputation points to downvote that old answer (and if I could downvote it 300 times for 300 Reputation I'd do so instantly). I finally found (one of) the roots for all those scaling-table code fragments. That thing should be pruned from the internet!
    – Skillmon
    Commented Sep 13, 2023 at 6:47

1 Answer 1

0

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}
2
  • 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
    Commented Sep 14, 2023 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. Commented Sep 14, 2023 at 20:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .