我试图获取由多列分隔的两个多行,但它想在表中添加一个额外的行。我的代码是:
\documentclass[]{article}
\usepackage{multirow,booktabs}
\begin{document}
\begin{table}[!htbp]
\begin{center}
\caption{Stuff.}
\begin{tabular}{cc|ccc|cc|ccc}
\toprule
\multicolumn{5}{c|}{Single Smoothing (SS)}&\multicolumn{5}{c}{Double Smoothing (DS)}\\
\midrule
Measure & Method & $h=1$ & $h=6$ & $h=12$ & Measure & Method & $h=1$ & $h=6$ & $h=12$ \\
\midrule
\multirow{4}{*}{sME} &&&&& \multirow{4}{*}{sME} \\
& SS & -0.312 & -8.605 & -3.342 & & DS & -0.315 & -0.175 & -0.238 \\
& Mean & -0.664 & 0.462 & -0.543 & & Mean & -0.484 & -0.290 & -0.308 \\
& Naive & 0.064 & -0.433 & -0.589 & & Naive & -1.364 & -0.786 & 0.108 \\
& Autobox & -0.578 & -1.947 & -0.702 & & Autobox & -1.784 & -0.201 & -0.294\\
\bottomrule
\end{tabular}
\end{center}
\end{table}
\end{document}
答案1
由于您没有在带有 的行中放置任何内容,因此您会得到额外的行\multirows
。尝试以下操作:
\documentclass[]{article}
\usepackage{multirow,booktabs}
\begin{document}
\begin{table}[!htbp]
\begin{center}
\caption{Stuff.}
\begin{tabular}{cc|ccc|cc|ccc}
\toprule
\multicolumn{5}{c|}{Single Smoothing (SS)}&\multicolumn{5}{c}{Double Smoothing (DS)}\\
\midrule
Measure & Method & $h=1$ & $h=6$ & $h=12$ & Measure & Method & $h=1$ & $h=6$ & $h=12$ \\
\midrule
\multirow{4}{*}{sME} & SS & -0.312 & -8.605 & -3.342 & \multirow{4}{*}{sME} & DS & -0.315 & -0.175 & -0.238 \\
% & SS & -0.312 & -8.605 & -3.342 & & DS & -0.315 & -0.175 & -0.238 \\
& Mean & -0.664 & 0.462 & -0.543 & & Mean & -0.484 & -0.290 & -0.308 \\
& Naive & 0.064 & -0.433 & -0.589 & & Naive & -1.364 & -0.786 & 0.108 \\
& Autobox & -0.578 & -1.947 & -0.702 & & Autobox & -1.784 & -0.201 & -0.294\\
\bottomrule
\end{tabular}
\end{center}
\end{table}
\end{document}
PS:你确定要那些垂直线吗?软件包booktabs
强调你不需要。下面是没有这些垂直线的替代方案:
\documentclass[]{article}
\usepackage{multirow,booktabs}
\begin{document}
\begin{table}[!htbp]
\begin{center}
\caption{Stuff.}
\begin{tabular}{cccccccccc}
\toprule
\multicolumn{5}{c}{Single Smoothing (SS)}&\multicolumn{5}{c}{Double Smoothing (DS)}\\
\cmidrule(lr){1-5} \cmidrule(lr){6-10}
Measure & Method & $h=1$ & $h=6$ & $h=12$ & Measure & Method & $h=1$ & $h=6$ & $h=12$ \\
\cmidrule(lr){1-5} \cmidrule(lr){6-10}
\multirow{4}{*}{sME} & SS & -0.312 & -8.605 & -3.342 & \multirow{4}{*}{sME} & DS & -0.315 & -0.175 & -0.238 \\
% & SS & -0.312 & -8.605 & -3.342 & & DS & -0.315 & -0.175 & -0.238 \\
& Mean & -0.664 & 0.462 & -0.543 & & Mean & -0.484 & -0.290 & -0.308 \\
& Naive & 0.064 & -0.433 & -0.589 & & Naive & -1.364 & -0.786 & 0.108 \\
& Autobox & -0.578 & -1.947 & -0.702 & & Autobox & -1.784 & -0.201 & -0.294\\
\bottomrule
\end{tabular}
\end{center}
\end{table}
\end{document}
你可以说 \cmidrule(l){i-j}
或\cmidrule(r){i-j}
或分别\cmidrule(lr){i-j}
缩短\cmidrule
左侧、右侧或两侧。
答案2
我建议进行以下布局改进:将表格分成两个子表,并使用siunitx
更好的格式设置第 3 至第 5 列中的数字:
\documentclass[]{article}
\usepackage[showframe]{geometry}
\usepackage{multirow,booktabs, subcaption}
\usepackage{siunitx}
\begin{document}
\begin{table}[!htbp]
\centering\setlength{\tabcolsep}{4pt}
\sisetup{table-format=-1.3, table-number-alignment=center}
\caption{Stuff.}
\noindent\begin{subtable}{0.48\linewidth}\centering
\caption{Single Smoothing (SS)}
\begin{tabular}{cc*{3}{S}}
\toprule
Measure & Method & {$h=1$} & {$h=6$} & {$h=12$} \\
\midrule
\multirow{4}{*}{sME} & SS & -0.312 & -8.605 & -3.342 \\
& Mean & -0.664 & 0.462 & -0.543 \\
& Naive & 0.064 & -0.433 & -0.589 \\
& Autobox & -0.578 & -1.947 & -0.702 \\
\bottomrule
\end{tabular}
\end{subtable}
\hfill
\begin{subtable}{0.48\linewidth}\centering
\caption{Double Smoothing (DS)}
\begin{tabular}{cc*{3}{S}}
\toprule
Measure & Method & {$h=1$} & {$h=6$} & {$h=12$} \\
\midrule
\multirow{4}{*}{sME} & DS & -0.315 & -0.175 & -0.238 \\
& Mean & -0.484 & -0.290 & -0.308 \\
& Naive & -1.364 & -0.786 & 0.108 \\
& Autobox & -1.784 & -0.201 & -0.294\\
\bottomrule
\end{tabular}
\end{subtable}
\end{table}
\end{document}