为什么此代码不起作用,运行后我的表格没有完全显示,
\usepackage{booktabs}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\begin{table*}\centering
\ra{1.3}
\begin{tabular}{@{}rrrrcrrrcrrr@{}}\toprule
& \multicolumn{3}{c}{$w = 8$} & \phantom{abc}& \multicolumn{3}{c}{$w = 16$} &
\phantom{abc} & \multicolumn{3}{c}{$w = 32$}\\
\cmidrule{2-4} \cmidrule{6-8} \cmidrule{10-12}
& $t=0$ & $t=1$ & $t=2$ && $t=0$ & $t=1$ & $t=2$ && $t=0$ & $t=1$ & $t=2$\\ \midrule
$dir=1$\\
$c$ & 0.0790 & 0.1692 & 0.2945 && 0.3670 & 0.7187 & 3.1815 && -1.0032 & -1.7104 & -21.7969\\
$c$ & -0.8651& 50.0476& 5.9384&& -9.0714& 297.0923& 46.2143&& 4.3590& 34.5809& 76.9167\\
$c$ & 124.2756& -50.9612& -14.2721&& 128.2265& -630.5455& -381.0930&& -121.0518& -137.1210& -220.2500\\
$dir=0$\\
$c$ & 0.0357& 1.2473& 0.2119&& 0.3593& -0.2755& 2.1764&& -1.2998& -3.8202& -1.2784\\
$c$ & -17.9048& -37.1111& 8.8591&& -30.7381& -9.5952& -3.0000&& -11.1631& -5.7108& -15.6728\\
$c$ & 105.5518& 232.1160& -94.7351&& 100.2497& 141.2778& -259.7326&& 52.5745& 10.1098& -140.2130\\
\bottomrule
\end{tabular}
\caption{Caption}
\end{table*}
答案1
您可以使表格适合标准文本宽度:
\documentclass[twocolumn]{article}
\usepackage{booktabs,siunitx}
\newcommand{\mc}[3]{\multicolumn{#1}{#2}{#3}}
\begin{document}
\begin{table*}
\centering
\setlength{\tabcolsep}{0pt}
\begin{tabular*}{\textwidth}{
@{\extracolsep{\fill}}
c
S[table-format=-2.4]
S[table-format=-2.4]
S[table-format=-2.4]
S[table-format=-2.4]
S[table-format=-3.4]
S[table-format=-3.4]
S[table-format=-3.4]
S[table-format=-3.4]
S[table-format=-3.4]
}
\toprule
& \mc{3}{c}{$w = 8$} & \mc{3}{c}{$w = 16$} & \mc{3}{c}{$w = 32$}\\
\cmidrule{2-4} \cmidrule{5-7} \cmidrule{8-10}
& {$t=0$} & {$t=1$} & {$t=2$}
& {$t=0$} & {$t=1$} & {$t=2$}
& {$t=0$} & {$t=1$} & {$t=2$} \\
\midrule
\mc{10}{@{}l}{$\mathit{dir}=1$} \\
$c$ & 0.0790 & 0.1692 & 0.2945 & 0.3670 & 0.7187 & 3.1815 & -1.0032 & -1.7104 & -21.7969\\
$c$ & -0.8651 & 50.0476 & 5.9384 & -9.0714 & 297.0923 & 46.2143 & 4.3590 & 34.5809 & 76.9167\\
$c$ & 124.2756 & -50.9612 & -14.2721 & 128.2265 & -630.5455 & -381.0930 & -121.0518 & -137.1210 & -220.2500\\
\midrule
\mc{10}{@{}l}{$\mathit{dir}=0$}\\
$c$ & 0.0357 & 1.2473 & 0.2119 & 0.3593 & -0.2755 & 2.1764 & -1.2998 & -3.8202 & -1.2784\\
$c$ & -17.9048 & -37.1111 & 8.8591 & -30.7381 & -9.5952 & -3.0000 & -11.1631 & -5.7108 & -15.6728\\
$c$ & 105.5518 & 232.1160 & -94.7351 & 100.2497 & 141.2778 & -259.7326 & 52.5745 & 10.1098 & -140.2130\\
\bottomrule
\end{tabular*}
\caption{Caption}
\end{table*}
\end{document}
在前四个数字列中,格式是-2.4
因为减号比附加数字更宽。
如果表格不适合,请\small
在其前面添加,或者在困难的情况下添加\footnotesize
。
答案2
你的桌子有两个主要问题:
- 您不需要添加虚拟的列来分隔 s
\cmidrule
,因为有以下选项(lr)
(l
= 左边的线更短,r
= 右边的线更短) - 您的表格太宽,不适合一页,我建议使用
sideways
并横向打印。(由于您没有发布完整的 MWE,所以我不知道您使用的是哪个文档类,我使用了book
。)
此外,我还添加了dcolumn
包以便更好地将您的数字与小数点对齐(当然,这是可选的)。
\documentclass{book}
\usepackage{array}
\usepackage{multirow}
\usepackage{booktabs}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\usepackage{rotating}
\usepackage{dcolumn}
\newcolumntype{d}{D{.}{.}{4}}
\begin{document}
\begin{sidewaystable}
\centering
\ra{1.3}
\begin{tabular}{@{}r*9{d}@{}}\toprule
& \multicolumn{3}{c}{$w = 8$} & \multicolumn{3}{c}{$w = 16$} & \multicolumn{3}{c}{$w = 32$}\\
\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(l){8-10}
& \multicolumn{1}{r}{$t=0$} & \multicolumn{1}{r}{$t=1$} & \multicolumn{1}{r}{$t=2$} & \multicolumn{1}{r}{$t=0$} & \multicolumn{1}{r}{$t=1$} & \multicolumn{1}{r}{$t=2$} & \multicolumn{1}{r}{$t=0$} & \multicolumn{1}{r}{$t=1$} & \multicolumn{1}{r@{}}{$t=2$}\\ \midrule
$dir=1$\\
$c$ & 0.0790 & 0.1692 & 0.2945 & 0.3670 & 0.7187 & 3.1815 & -1.0032 & -1.7104 & -21.7969\\
$c$ & -0.8651& 50.0476& 5.9384& -9.0714& 297.0923& 46.2143& 4.3590& 34.5809& 76.9167\\
$c$ & 124.2756& -50.9612& -14.2721& 128.2265& -630.5455& -381.0930& -121.0518& -137.1210& -220.2500\\
$dir=0$\\
$c$ & 0.0357& 1.2473& 0.2119& 0.3593& -0.2755& 2.1764& -1.2998& -3.8202& -1.2784\\
$c$ & -17.9048& -37.1111& 8.8591& -30.7381& -9.5952& -3.0000& -11.1631& -5.7108& -15.6728\\
$c$ & 105.5518& 232.1160& -94.7351& 100.2497& 141.2778& -259.7326& 52.5745& 10.1098& -140.2130\\
\bottomrule
\end{tabular}
\caption{Caption}
\end{sidewaystable}
\end{document}