我正在尝试制作一个带有文本的 24*9 表格。如果运行下面的代码,您会看到右侧的列在表格之外。我猜这可能与第一列和第二列也连接在一起有关,列内的值之间没有空格。
感谢您提供的任何意见。谢谢。
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[h!]
\small
\caption{DM Test}
\label{table:5:2}
\begin{tabular*}{\textwidth}{c @{\extracolsep{\fill}} lllllllll}
\toprule
{} & \multicolumn{2}{c}{Zone 1} & \multicolumn{2}{c}{Zone 2}
& \multicolumn{2}{c}{Zone 3} & \multicolumn{2}{c}{Zone 4} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(l){8-9}
{} & 2021 & 2022 & 2021 & 2022 & 2021 & 2022 & 2021 & 2022 \\
\midrule
1 & Auto & Auto & Auto & Auto & Auto & Auto & Auto & Auto \\
2 & Auto & Auto* & Auto & Auto & LEAR & LEAR & Auto & Auto* \\
3 & Auto & LEAR*** & Auto & Auto*** & LEAR & LEAR & LEAR & LEAR*** \\
4 & Auto & Expert*** & Auto & Expert*** & LEAR & LEAR & LEAR & LEAR** \\
5 & Auto*** & Expert** & Expert*** & Expert*** & LEAR & LEAR & LEAR & Expert*** \\
6 & Expert** & Expert** & Expert** & Expert** & Expert** & LEAR & Expert** & Expert*** \\
7 & Expert* & Expert* & Expert* & Expert* & Expert & LEAR* & Expert & LEAR*** \\
8 & Expert & Expert*** & LEAR*** & LEAR*** & Expert** & LEAR & Expert*** & LEAR** \\
9 & Expert & Expert*** & Expert*** & Expert** & Expert*** & LEAR & Expert*** & LEAR* \\
10 & Expert & LEAR*** & Expert* & Expert*** & LEAR*** & LEAR & LEAR** & LEAR*** \\
11 & Expert & Expert*** & Expert*** & Expert*** & Expert** & LEAR* & Expert*** & LEAR*** \\
12 & Expert & Expert* & Expert** & Expert* & Expert** & LEAR & Expert*** & Auto*** \\
13 & Expert & Expert** & Expert & Expert* & Expert** & LEAR & Expert*** & LEAR*** \\
14 & Expert & Expert** & Expert* & Expert* & Expert* & LEAR* & Expert*** & LEAR*** \\
15 & Expert* & Expert** & Expert** & Expert* & Expert & LEAR*** & Expert*** & LEAR*** \\
16 & Expert & Expert* & Expert** & Expert** & Expert & Expert*** & Expert*** & LEAR*** \\
17 & Expert* & Expert*** & Expert*** & Expert*** & Expert*** & Expert* & Expert*** & LEAR*** \\
18 & Expert & LEAR** & LEAR*** & LEAR*** & Expert*** & Naive** & LEAR** & Naive** \\
19 & Naive*** & LEAR*** & Naive*** & LEAR*** & Naive*** & Naive & Expert*** & Naive \\
20 & Naive*** & LEAR*** & Naive** & LEAR*** & Naive** & Naive* & LEAR* & Naive \\
21 & Naive & LEAR** & Naive & LEAR** & Naive* & LEAR* & LEAR*** & Naive \\
22 & Naive & LEAR** & Naive & LEAR* & Naive & LEAR** & Expert** & Naive* \\
23 & Naive & LEAR** & Naive & LEAR** & Naive & LEAR* & Expert** & Naive* \\
24 & Naive & LEAR* & Naive & LEAR* & Naive & LEAR & Naive & Naive* \\
\bottomrule
\end{tabular*}
\smallskip
\footnotesize
\end{table}
\end{document}
答案1
我建议您设置\tabcolsep
为0pt
,让 LaTeX 计算出可用的列间空白量。
\documentclass{article}
\usepackage[letterpaper,margin=1in]{geometry} % set applicable page parameter values
\usepackage{booktabs}
\begin{document}
\begin{table}[h!]
%\small % not needed
\setlength\tabcolsep{0pt} % let LaTeX figure out intercol. whitespace
\caption{DM Test\strut}
\label{table:5:2}
\begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} *{8}{l}}
\toprule
& \multicolumn{2}{c}{Zone 1} & \multicolumn{2}{c}{Zone 2}
& \multicolumn{2}{c}{Zone 3} & \multicolumn{2}{c}{Zone 4} \\
\cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9}
& 2021 & 2022 & 2021 & 2022 & 2021 & 2022 & 2021 & 2022 \\
\midrule
1 & Auto & Auto & Auto & Auto & Auto & Auto & Auto & Auto \\
2 & Auto & Auto* & Auto & Auto & LEAR & LEAR & Auto & Auto* \\
3 & Auto & LEAR*** & Auto & Auto*** & LEAR & LEAR & LEAR & LEAR*** \\
4 & Auto & Expert*** & Auto & Expert*** & LEAR & LEAR & LEAR & LEAR** \\
5 & Auto*** & Expert** & Expert*** & Expert*** & LEAR & LEAR & LEAR & Expert*** \\
6 & Expert** & Expert** & Expert** & Expert** & Expert** & LEAR & Expert** & Expert*** \\
\addlinespace
7 & Expert* & Expert* & Expert* & Expert* & Expert & LEAR* & Expert & LEAR*** \\
8 & Expert & Expert*** & LEAR*** & LEAR*** & Expert** & LEAR & Expert*** & LEAR** \\
9 & Expert & Expert*** & Expert*** & Expert** & Expert*** & LEAR & Expert*** & LEAR* \\
10 & Expert & LEAR*** & Expert* & Expert*** & LEAR*** & LEAR & LEAR** & LEAR*** \\
11 & Expert & Expert*** & Expert*** & Expert*** & Expert** & LEAR* & Expert*** & LEAR*** \\
12 & Expert & Expert* & Expert** & Expert* & Expert** & LEAR & Expert*** & Auto*** \\
\addlinespace
13 & Expert & Expert** & Expert & Expert* & Expert** & LEAR & Expert*** & LEAR*** \\
14 & Expert & Expert** & Expert* & Expert* & Expert* & LEAR* & Expert*** & LEAR*** \\
15 & Expert* & Expert** & Expert** & Expert* & Expert & LEAR*** & Expert*** & LEAR*** \\
16 & Expert & Expert* & Expert** & Expert** & Expert & Expert*** & Expert*** & LEAR*** \\
17 & Expert* & Expert*** & Expert*** & Expert*** & Expert*** & Expert* & Expert*** & LEAR*** \\
18 & Expert & LEAR** & LEAR*** & LEAR*** & Expert*** & Naive** & LEAR** & Naive** \\
\addlinespace
19 & Naive*** & LEAR*** & Naive*** & LEAR*** & Naive*** & Naive & Expert*** & Naive \\
20 & Naive*** & LEAR*** & Naive** & LEAR*** & Naive** & Naive* & LEAR* & Naive \\
21 & Naive & LEAR** & Naive & LEAR** & Naive* & LEAR* & LEAR*** & Naive \\
22 & Naive & LEAR** & Naive & LEAR* & Naive & LEAR** & Expert** & Naive* \\
23 & Naive & LEAR** & Naive & LEAR** & Naive & LEAR* & Expert** & Naive* \\
24 & Naive & LEAR* & Naive & LEAR* & Naive & LEAR & Naive & Naive* \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
答案2
\textwidth
您的表格比文档类的默认表格要宽很多ąrticle
,因此我建议使用geometry
包并使其更大- 如果这不是一个选项,那么你需要把
landscape
面向表格的页面 - 我想您正在寻找
threeparttable
或talltblr
相当于以下的tabularray
包:
\documentclass{article}
\usepackage{geometry} % needed! otherwise cells will overlap
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{table}[h!]
\SetTblrStyle{note}{font=\footnotesize}
\begin{talltblr}[
\small
caption = {DM Test},
label = {table:5:2},
note{} = {some text, *: \dots,
**: \dots and
***: \dots.
}
]{colspec = {@{} r *{8}{X[l]} @{}},
row{3-Z}= {rowsep = 0pt},
row{even[3-X]} = {belowsep=1ex}
}
\toprule
& \SetCell[c=2]{c} Zone 1
& & \SetCell[c=2]{c} Zone 2
& & \SetCell[c=2]{c} Zone 3
& & \SetCell[c=2]{c} Zone 4
& \\
\cmidrule[r]{2-3} \cmidrule[r]{4-5} \cmidrule[r]{6-7} \cmidrule{8-9}
& 2021 & 2022 & 2021 & 2022 & 2021 & 2022 & 2021 & 2022 \\
\midrule
1 & Auto & Auto & Auto & Auto & Auto & Auto & Auto & Auto \\
2 & Auto & Auto* & Auto & Auto & LEAR & LEAR & Auto & Auto* \\
3 & Auto & LEAR*** & Auto & Auto*** & LEAR & LEAR & LEAR & LEAR*** \\
4 & Auto & Expert*** & Auto & Expert*** & LEAR & LEAR & LEAR & LEAR** \\
5 & Auto*** & Expert** & Expert*** & Expert*** & LEAR & LEAR & LEAR & Expert*** \\
6 & Expert** & Expert** & Expert** & Expert** & Expert** & LEAR & Expert** & Expert*** \\
7 & Expert* & Expert* & Expert* & Expert* & Expert & LEAR* & Expert & LEAR*** \\
8 & Expert & Expert*** & LEAR*** & LEAR*** & Expert** & LEAR & Expert*** & LEAR** \\
9 & Expert & Expert*** & Expert*** & Expert** & Expert*** & LEAR & Expert*** & LEAR* \\
10 & Expert & LEAR*** & Expert* & Expert*** & LEAR*** & LEAR & LEAR** & LEAR*** \\
11 & Expert & Expert*** & Expert*** & Expert*** & Expert** & LEAR* & Expert*** & LEAR*** \\
12 & Expert & Expert* & Expert** & Expert* & Expert** & LEAR & Expert*** & Auto*** \\
13 & Expert & Expert** & Expert & Expert* & Expert** & LEAR & Expert*** & LEAR*** \\
14 & Expert & Expert** & Expert* & Expert* & Expert* & LEAR* & Expert*** & LEAR*** \\
15 & Expert* & Expert** & Expert** & Expert* & Expert & LEAR*** & Expert*** & LEAR*** \\
16 & Expert & Expert* & Expert** & Expert** & Expert & Expert*** & Expert*** & LEAR*** \\
17 & Expert* & Expert*** & Expert*** & Expert*** & Expert*** & Expert* & Expert*** & LEAR*** \\
18 & Expert & LEAR** & LEAR*** & LEAR*** & Expert*** & Naive** & LEAR** & Naive** \\
19 & Naive*** & LEAR*** & Naive*** & LEAR*** & Naive*** & Naive & Expert*** & Naive \\
20 & Naive*** & LEAR*** & Naive** & LEAR*** & Naive** & Naive* & LEAR* & Naive \\
21 & Naive & LEAR** & Naive & LEAR** & Naive* & LEAR* & LEAR*** & Naive \\
22 & Naive & LEAR** & Naive & LEAR* & Naive & LEAR** & Expert** & Naive* \\
23 & Naive & LEAR** & Naive & LEAR** & Naive & LEAR* & Expert** & Naive* \\
24 & Naive & LEAR* & Naive & LEAR* & Naive & LEAR & Naive & Naive* \\
\bottomrule
\end{talltblr}
\end{table}
\end{document}