簡體   English   中英

使表格大小與乳膠中的頁面大小相適應

[英]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[10pt]{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. 不相關,但您應該您的\\caption{...}之后有一個命令\\label{...} \\caption{...}

  2. 不要將垂直線(最好避免它們)與包裝書booktabstoprulemidrulebottomrulemidrule bottomrule

  3. 這應該有希望回答你的問題:嘗試列ytpe X從包裝tabularx更好地伸展列的寬度(我猜你有一個比這更列的表)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM