Fit table 大小与乳胶中的页面大小

Fit table size with the page size in latex

我有许多表格,列数不同,应该适合页面大小。为此,我使用了类似于下面的代码:

\begin{table}
    \caption{Values}
    \centering
    \resizebox{\linewidth}{!}{
        \begin{tabular}{!{\vrule}l!{\vrule}l!{\vrule}l!{\vrule}l!{\vrule}l!{\vrule}l} 
            \toprule
            DS             & Criterion1 & Criterion2 & Criterion3 & Criterion4  \ 
            \midrule
            DS1 & V1 & V2 & V3  & V4 \ 
            \midrule
            DS2       & V5 & V6 & V7 & V8 \ 
            \midrule
            DS3       & V9 & V10 & V11 & V12 \ 
            \midrule
            DS4 & V13 & V14 & V15 & V16 \
            \botrule
        \end{tabular}
    }
\end{table}

此代码生成表格但显示错误类型:数组 arg 中的非法字符。 我不明白这个错误。

如有任何帮助,我们将不胜感激。

我建议编辑您的代码:

\documentclass{article}
\usepackage{tabularx,booktabs}

\begin{document}
\noindent
\begin{table}
  \caption{Values}
  \label{tab:n}
  \centering
  \begin{tabularx}{\textwidth}{*{5}{X}}
    \toprule
    DS  & Criterion1 & Criterion2 & Criterion3 & Criterion4 \ 
    \midrule
    DS1 & V1         & V2         & V3         & V4 \ 
    \midrule
    DS2 & V5         & V6         & V7         & V8 \ 
    \midrule
    DS3 & V9         & V10        & V11        & V12 \ 
    \midrule
    DS4 & V13        & V14        & V15        & V16 \
    \bottomrule
  \end{tabularx}
\end{table}
\end{document}

  1. 不相关,但你应该有一个命令 \label{...} after 或者在你的 \caption{...}.

  2. 不要将垂直线与包装中的水平线混在一起 booktabstoprulemidrulebottomrule).

  3. 这应该有望回答您的问题:尝试使用包 tabularx 中的列类型 X 以更好地拉伸列的宽度(我猜您的表格包含更多列比这一个)。