我有以下脚本,可以生成我正在尝试正确格式化的表格。
\documentclass[12pt]{article}
\usepackage{float}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{multirow}
\begin{document}
\begin{table}[H]
\begin{tabular}{c@{\qquad}cccc@{\qquad}ccc@{\qquad}ccc@{\qquad}c}
\toprule
\multirow{2}{*}{\raisebox{-\heavyrulewidth}{Scenarios}} & \multicolumn{4}{c} {GAM} & \multicolumn{3}{c}{SCAM} & \multicolumn{3}{c}{Krig} \\
\cmidrule{2-10}
& {\tt tp} & {\tt cr} & {\tt ps} & {\tt ad} & {\tt mpi} & {\tt cv} & {\tt micv} & {\tt mat} & {\tt sph} & {\tt exp}\\
\midrule
Uniform & 1 & 2 & 3 & 1 & 2 & 3 \\
1 dominant & 1 & 2 & 3 & 1 & 2 & 3 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
标题“GAM”、“SCAM”和“Krig”略微偏离中心(向右推)。如何修复?
另外,我需要将“Krig”标题下方的水平线进一步向右延伸。我尝试将 增加到,10
但收到错误。15
\cmidrule
有人知道该怎么修复吗?如能得到任何帮助,我们将不胜感激。
答案1
不要更改某些列的列间距,而是添加一些空列。此外,要微调多行单元格的垂直位置,请使用可选参数 而\multirow
不是\raisebox
:
\documentclass[12pt]{article}
\usepackage{float}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{array, multirow}
\begin{document}
\begin{table}[H]
\begin{tabular}{l@{\qquad}*{14}{c}}
\toprule
\multirow{2}{*}[-\heavyrulewidth]{Scenarios}} & \multicolumn{4}{c} {GAM} & & \multicolumn{3}{c}{SCAM} & & \multicolumn{3}{c}{Krig} \\
\cmidrule(r){2-5} \cmidrule(lr){7-9} \cmidrule(lr){11-13}
& {\tt tp} & {\tt cr} & {\tt ps} & {\tt ad} & & {\tt mpi} & {\tt cv} & {\tt micv} & & {\tt mat} & {\tt sph} & {\tt exp}\\
\midrule
Uniform & 1 & 2 & 3 & 1 & & 2 & 3 \\
1 dominant & 1 & 2 & 3 & 1 & & 2 & 3 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
使用可选的间距(收缩)参数\cmidrule
;收缩跨越的\cmidrule(<side>){<cols>}
规则,其中标识规则的左侧或右侧。这有助于水平地将子标题与表格的其余部分分开。<cols>
<sides>
<sides>
l
r
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ l *{4}{c} *{3}{c} *{3}{c} }
\toprule
& \multicolumn{4}{c}{GAM} & \multicolumn{3}{c}{SCAM} & \multicolumn{3}{c}{Krig} \\
\cmidrule(lr){2-5} % GAM
\cmidrule(lr){6-8} % SCAM
\cmidrule(lr){9-11} % Krig
Scenarios &
\texttt{tp} & \texttt{cr} & \texttt{ps} & \texttt{ad} & % GAM
\texttt{mpi} & \texttt{cv} & \texttt{micv} & % SCAM
\texttt{mat} & \texttt{sph} & \texttt{exp} \\ % Krig
\midrule
Uniform &
1 & 2 & 3 & 4 & % GAM
5 & 6 & 7 & % SCAM
8 & 9 & 10 \\ % Krig
1 dominant &
1 & 2 & 3 & 4 & % GAM
5 & 6 & 7 & % SCAM
8 & 9 & 10 \\ % Krig
\bottomrule
\end{tabular}
\end{document}