有人能帮我用多列和 cmidrule 对齐表格吗?我有一张 19 列的长表格,用 \tiny 将表格放到页面上,但布局不太好。我想要像第二张图片那样的东西。
\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}% raggedleft column X
\begin{table}[htbp]
\tiny
\centering
\caption{ARMA order selection}
\begin{tabular}{*{19}{l}}
\toprule
& \multicolumn{2}{c}{DJI} & \multicolumn{2}{c}{NIKKEI}
& \multicolumn{2}{c}{TSX} & \multicolumn{2}{c}{FTSE} & \multicolumn{2}{c}{DAX} & \multicolumn{2}{c}{CAC} & \multicolumn{2}{c}{SSE} & \multicolumn{2}{c}{BVSP} & \multicolumn{2}{c}{HSI} \\
\cmidrule(lr){2-3}
\cmidrule(lr){4-5}
\cmidrule(lr){6-7}
\cmidrule(lr){8-9}
\cmidrule(lr){10-11}
\cmidrule(lr){12-13}
\cmidrule(lr){14-15}
\cmidrule(lr){16-17}
\cmidrule(lr){18-19}
& AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC \\
\midrule
ARMA(1,0) & 4936.9 & 4952.8 & 5288.5 & 5304.4 & 4528.1 & 4544.0 & 4733.0 & 4748.9 & 5312.9 & 5328.8 & 5242.3 & 5258.2 & 5588.9 & 5604.9 & 6153.9 & 6169.8 & 4967.9 & 4983.8 \\
ARMA(0,1) & 4944.3 & 4960.3 & 5288.6 & 5304.6 & 4533.6 & 4549.5 & 4733.0 & 4748.9 & 5312.9 & 5328.9 & 5242.4 & 5258.3 & 5588.9 & 5604.9 & 6154.8 & 6170.8 & 4967.9 & 4983.8 &\\
ARMA(1,1) & 4922.0 & 4943.3 & 5285.5 & 5306.8 & 4506.4 & 4527.6 & 4735.0 & 4756.2 & 5314.8 & 5336.1 & 5244.0 & 5265.3 & 5590.6 & 5611.9 & 6155.5 & 6176.8 & 4969.9 & 4991.2 &\\
ARMA(2,1) & 4922.7 & 4949.3 & 5287.3 & 5313.9 & 4506.0 & 4532.5 & 4735.2 & 4761.7 & 5314.0 & 5340.6 & 5244.4 & 5271.1 & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 &\\
ARMA(1,2) & 4922.7 & 4949.2 & 5287.3 & 5313.9 & 4505.9 & 4532.5 & 4735.3 & 4761.9 & 5314.0 & 5340.6 & 5244.2 & 5270.8 & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 &\\
ARMA(2,2) & 4919.3 & 4951.2 & 5289.3 & 5321.2 & 4505.7 & 4537.6 & 4719.1 & 4751.0 & 5316.8 & 5348.7 & 5233.9 & 5265.8 & 5594.0 & 5625.9 & 6157.0 & 6188.9 & 4966.2 & 4998.1 &\\
\bottomrule
\end{tabular}
\label{Selection of ARMA orders}
\end{table}
答案1
以 AIC 和 BIC 为中心并使用\arraystretch
有很大帮助。
\documentclass{article}
\usepackage[textwidth=30cm]{geometry}
\usepackage{booktabs}
\newcommand{\SH}{\multicolumn{1}{c}{AIC} & \multicolumn{1}{c}{BIC}} % subhead
\begin{document}
\begin{table}[htbp]
\tiny
\centering
\setlength{\abovetopsep}{10pt}
\renewcommand{\arraystretch}{1.2}
\caption{ARMA order selection}
\begin{tabular}{*{19}{l}}
\toprule
& \multicolumn{2}{c}{DJI} & \multicolumn{2}{c}{NIKKEI}
& \multicolumn{2}{c}{TSX} & \multicolumn{2}{c}{FTSE} & \multicolumn{2}{c}{DAX} & \multicolumn{2}{c}{CAC} & \multicolumn{2}{c}{SSE} & \multicolumn{2}{c}{BVSP} & \multicolumn{2}{c}{HSI} \\
\cmidrule(lr){2-3}
\cmidrule(lr){4-5}
\cmidrule(lr){6-7}
\cmidrule(lr){8-9}
\cmidrule(lr){10-11}
\cmidrule(lr){12-13}
\cmidrule(lr){14-15}
\cmidrule(lr){16-17}
\cmidrule(lr){18-19}
& \SH & \SH & \SH & \SH & \SH & \SH & \SH & \SH & \SH \\
\midrule
ARMA(1,0) & 4936.9 & 4952.8 & 5288.5 & 5304.4 & 4528.1 & 4544.0 & 4733.0 & 4748.9 & 5312.9 & 5328.8 & 5242.3 & 5258.2 & 5588.9 & 5604.9 & 6153.9 & 6169.8 & 4967.9 & 4983.8 \\
ARMA(0,1) & 4944.3 & 4960.3 & 5288.6 & 5304.6 & 4533.6 & 4549.5 & 4733.0 & 4748.9 & 5312.9 & 5328.9 & 5242.4 & 5258.3 & 5588.9 & 5604.9 & 6154.8 & 6170.8 & 4967.9 & 4983.8 \\
ARMA(1,1) & 4922.0 & 4943.3 & 5285.5 & 5306.8 & 4506.4 & 4527.6 & 4735.0 & 4756.2 & 5314.8 & 5336.1 & 5244.0 & 5265.3 & 5590.6 & 5611.9 & 6155.5 & 6176.8 & 4969.9 & 4991.2 \\
ARMA(2,1) & 4922.7 & 4949.3 & 5287.3 & 5313.9 & 4506.0 & 4532.5 & 4735.2 & 4761.7 & 5314.0 & 5340.6 & 5244.4 & 5271.1 & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 \\
ARMA(1,2) & 4922.7 & 4949.2 & 5287.3 & 5313.9 & 4505.9 & 4532.5 & 4735.3 & 4761.9 & 5314.0 & 5340.6 & 5244.2 & 5270.8 & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 \\
ARMA(2,2) & 4919.3 & 4951.2 & 5289.3 & 5321.2 & 4505.7 & 4537.6 & 4719.1 & 4751.0 & 5316.8 & 5348.7 & 5233.9 & 5265.8 & 5594.0 & 5625.9 & 6157.0 & 6188.9 & 4966.2 & 4998.1 \\
\bottomrule
\end{tabular}
\label{Selection of ARMA orders}
\end{table}
\end{document}
答案2
为了使您的代码可编译,请将其替换& \\
为\\
。否则,您最终会收到错误消息Extra alignment tab has been changed to \cr.
。一旦收到错误消息,请不要查看生成的 pdf 文件,而是先修复错误。
现在代码编译正确了,我们可以看看输出,发现即使使用了\tiny
字体大小,表格仍然太宽,无法适应页面。因此我建议将其拆分。我还将水平对齐从左对齐改为居中。
\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{booktabs}
\usepackage{caption}
\begin{document}
\begin{table}[htbp]
\centering
\caption{ARMA order selection}
\begin{tabular}{l *{6}{c}}
\toprule
& \multicolumn{2}{c}{DJI} & \multicolumn{2}{c}{NIKKEI} & \multicolumn{2}{c}{TSX}
\\
\cmidrule(r){2-3}
\cmidrule(lr){4-5}
\cmidrule(l){6-7}
& AIC & BIC & AIC & BIC & AIC & BIC \\
\midrule
ARMA(1,0) & 4936.9 & 4952.8 & 5288.5 & 5304.4 & 4528.1 & 4544.0 \\
ARMA(0,1) & 4944.3 & 4960.3 & 5288.6 & 5304.6 & 4533.6 & 4549.5 \\
ARMA(1,1) & 4922.0 & 4943.3 & 5285.5 & 5306.8 & 4506.4 & 4527.6 \\
ARMA(2,1) & 4922.7 & 4949.3 & 5287.3 & 5313.9 & 4506.0 & 4532.5 \\
ARMA(1,2) & 4922.7 & 4949.2 & 5287.3 & 5313.9 & 4505.9 & 4532.5 \\
ARMA(2,2) & 4919.3 & 4951.2 & 5289.3 & 5321.2 & 4505.7 & 4537.6 \\
\midrule
& \multicolumn{2}{c}{FTSE} & \multicolumn{2}{c}{DAX} & \multicolumn{2}{c}{CAC} \\
\cmidrule(r){2-3}
\cmidrule(lr){4-5}
\cmidrule(l){6-7}
& AIC & BIC & AIC & BIC & AIC & BIC \\
\midrule
ARMA(1,0) & 4733.0 & 4748.9 & 5312.9 & 5328.8 & 5242.3 & 5258.2 \\
ARMA(0,1) & 4733.0 & 4748.9 & 5312.9 & 5328.9 & 5242.4 & 5258.3 \\
ARMA(1,1) & 4735.0 & 4756.2 & 5314.8 & 5336.1 & 5244.0 & 5265.3 \\
ARMA(2,1) & 4735.2 & 4761.7 & 5314.0 & 5340.6 & 5244.4 & 5271.1 \\
ARMA(1,2) & 4735.3 & 4761.9 & 5314.0 & 5340.6 & 5244.2 & 5270.8 \\
ARMA(2,2) & 4719.1 & 4751.0 & 5316.8 & 5348.7 & 5233.9 & 5265.8 \\
\midrule
& \multicolumn{2}{c}{SSE} & \multicolumn{2}{c}{BVSP} & \multicolumn{2}{c}{HSI} \\
\cmidrule(r){2-3}
\cmidrule(lr){4-5}
\cmidrule(l){6-7}
& AIC & BIC & AIC & BIC & AIC & BIC \\
\midrule
ARMA(1,0) & 5588.9 & 5604.9 & 6153.9 & 6169.8 & 4967.9 & 4983.8 \\
ARMA(0,1) & 5588.9 & 5604.9 & 6154.8 & 6170.8 & 4967.9 & 4983.8 \\
ARMA(1,1) & 5590.6 & 5611.9 & 6155.5 & 6176.8 & 4969.9 & 4991.2 \\
ARMA(2,1) & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 \\
ARMA(1,2) & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 \\
ARMA(2,2) & 5594.0 & 5625.9 & 6157.0 & 6188.9 & 4966.2 & 4998.1 \\
\bottomrule
\end{tabular}
\label{Selection of ARMA orders}
\end{table}
\begin{table}[htbp]
\centering
% \small
\caption{ARMA order selection}
\begin{tabular}{l*{10}{c}}
\toprule
& \multicolumn{2}{c}{DJI} & \multicolumn{2}{c}{NIKKEI}
& \multicolumn{2}{c}{TSX} & \multicolumn{2}{c}{FTSE} & \multicolumn{2}{c}{DAX} \\
\cmidrule(r){2-3}
\cmidrule(lr){4-5}
\cmidrule(lr){6-7}
\cmidrule(lr){8-9}
\cmidrule(l){10-11}
ARMA & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC \\
\midrule
(1,0) & 4936.9 & 4952.8 & 5288.5 & 5304.4 & 4528.1 & 4544.0 & 4733.0 & 4748.9 & 5312.9 & 5328.8 \\
(0,1) & 4944.3 & 4960.3 & 5288.6 & 5304.6 & 4533.6 & 4549.5 & 4733.0 & 4748.9 & 5312.9 & 5328.9 \\
(1,1) & 4922.0 & 4943.3 & 5285.5 & 5306.8 & 4506.4 & 4527.6 & 4735.0 & 4756.2 & 5314.8 & 5336.1 \\
(2,1) & 4922.7 & 4949.3 & 5287.3 & 5313.9 & 4506.0 & 4532.5 & 4735.2 & 4761.7 & 5314.0 & 5340.6 \\
(1,2) & 4922.7 & 4949.2 & 5287.3 & 5313.9 & 4505.9 & 4532.5 & 4735.3 & 4761.9 & 5314.0 & 5340.6 \\
(2,2) & 4919.3 & 4951.2 & 5289.3 & 5321.2 & 4505.7 & 4537.6 & 4719.1 & 4751.0 & 5316.8 & 5348.7 \\
\midrule
& \multicolumn{2}{c}{CAC} & \multicolumn{2}{c}{SSE} & \multicolumn{2}{c}{BVSP} & \multicolumn{2}{c}{HSI} \\
\cmidrule(r){2-3}
\cmidrule(lr){4-5}
\cmidrule(lr){6-7}
\cmidrule(l){8-9}
ARMA & AIC & BIC & AIC & BIC & AIC & BIC & AIC & BIC \\
\midrule
(1,0) & 5242.3 & 5258.2 & 5588.9 & 5604.9 & 6153.9 & 6169.8 & 4967.9 & 4983.8 \\
(0,1) & 5242.4 & 5258.3 & 5588.9 & 5604.9 & 6154.8 & 6170.8 & 4967.9 & 4983.8 \\
(1,1) & 5244.0 & 5265.3 & 5590.6 & 5611.9 & 6155.5 & 6176.8 & 4969.9 & 4991.2 \\
(2,1) & 5244.4 & 5271.1 & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 \\
(1,2) & 5244.2 & 5270.8 & 5592.3 & 5618.9 & 6157.5 & 6184.1 & 4970.7 & 4997.3 \\
(2,2) & 5233.9 & 5265.8 & 5594.0 & 5625.9 & 6157.0 & 6188.9 & 4966.2 & 4998.1 \\
\bottomrule
\end{tabular}
\label{Selection of ARMA orders}
\end{table}
\end{document}