当表格大小超出页面宽度时可以调整大小吗?

当表格大小超出页面宽度时可以调整大小吗?

我试图使用这里以确保我的表格适合页面宽度。我想重新定义表格环境,这样如果表格宽度超出页面宽度,此更改就会自动应用。有什么办法吗?

答案1

只是为了好玩:

\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}

相关内容