我有这个代码:
\documentclass[11pt]{article}
\usepackage[margin=2.5cm, showframe]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage{setspace}
\usepackage{lipsum}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage[skip=0.33\baselineskip]{caption}
\captionsetup[table]{
font=bf,
size=normalsize,
justification=centerlast,
labelsep=newline
}
\renewcommand\thetable{\Roman{table}}
\begin{document}
\def\arraystretch{1.5}
\begin{table}[!htb]
\centering
\setlength\tabcolsep{0pt}
\sisetup{table-format=2.2, group-separator={,}, group-minimum-digits=4}
\caption{\large{Name of a table that contains no useful knowledge}}
\parbox{\linewidth}{\footnotesize\lipsum[1]\vspace{2ex}}
\medskip\small\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}
l
S[table-format=-2.2]
*{6}{S}
}
\toprule
\multicolumn{1}{c}{\multirow{2}{*}{Group}}&
\multicolumn{1}{c}{\multirow{2}{*}{Total}}&
\multicolumn{5}{c}{Time--Series Averages of Cross--Sectional Average Monthly Attributes}\\\cline{3-7}
\multicolumn{2}{c}{}&{Value 1}&{Value 2}&{Value 3}&{Value 4}&{Value 5}\\\midrule
All &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\\midrule
Characteristic 1\\
Sub 1.1 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 1.2 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 1.3 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\\midrule
Characteristic 2\\
Sub 2.1 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 2.2 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 2.3 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\\midrule
Characteristic 3\\
Sub 3.1 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 3.2 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 3.3 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\\midrule
Characteristic 4\\
Sub 4.1 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 4.2 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 4.3 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
生成此表
由于某种原因,值 1 到 4 似乎分布均匀,但值 4 和 5 之间出现了大量水平空间。我曾尝试告诉 LaTeX 使用代码来均衡分布,但没有成功。我已经阅读这,但我想知道是否可以在环境内解决这个问题tabular*
。
答案1
正如@Zarko 在评论中指出的那样,跨越 5 列的标签比列的自然宽度总和还要宽。因此,我建议您从环境切换tabular*
到tabularx
环境。
另外,您可能需要考虑使用更少的水平线和更多的(垂直)空白。
\documentclass[11pt]{article}
\usepackage[margin=2.5cm,a4paper]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{caption,setspace,lipsum,\
booktabs,siunitx,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcommand\mC[1]{\multicolumn{1}{C}{#1}} % handy shortcut macro
\captionsetup{
font=bf,
size=normalsize,
justification=centerlast,
labelsep=newline,
skip=0.33\baselineskip
}
\renewcommand\thetable{\Roman{table}}
\begin{document}
\begin{table}[!htb]
\sisetup{table-format=2.2}
\caption{Name of a table that contains no useful knowledge}
\parbox{\linewidth}{\footnotesize\lipsum[1]\vspace{2ex}}
\small
\begin{tabularx}{\linewidth}{@{} l *{6}{S} @{}}
\toprule
Group & \mC{Total} &
\multicolumn{5}{c@{}}{Time-Series Averages of Cross-Sectional Average Monthly Attributes}
\\
\cmidrule(l){3-7}
&&\mC{Value 1}&\mC{Value 2}&\mC{Value 3}&\mC{Value 4}&\mC{Value 5}\\
\midrule
All &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
\addlinespace % \midrule
Characteristic 1\\
Sub 1.1 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 1.2 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 1.3 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
\addlinespace % \midrule
Characteristic 2\\
Sub 2.1 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 2.2 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 2.3 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
\addlinespace % \midrule
Characteristic 3\\
Sub 3.1 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 3.2 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 3.3 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
\addlinespace % \midrule
Characteristic 4\\
Sub 4.1 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 4.2 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
Sub 4.3 &11.11 &22.22 &33.33 &44.44 &55.55 &66.66\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}