本系列文章由 @yhl_leo 出品,转载请注明出处。
文章链接: http://blog.csdn.net/yhl_leo/article/details/52692655
简单整理一下表格中的分级表,以三线表Table 1为例:
这种非常规的一行一列的结构,尤其是表头部分,每个子表头下,又细分了三个子表头,这种用法也是很常见的,实现方法如下:
% Table 1
ewcommand{
a}[1]{
enewcommand{arraystretch}{#1}}
begin{table*}centering
caption{Caption}
a{1.2}
begin{tabular}{rrrrcrrrc} oprule
& multicolumn{3}{c}{$w = 8$} & phantom{abc}& multicolumn{3}{c}{$w = 16$} & phantom{abc} \
cmidrule{2-4} cmidrule{6-8}
& $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\
$c$ & -0.8651& 50.0476& 5.9384&& -9.0714& 297.0923& 46.\
$c$ & 124.2756& -50.9612& -14.2721&& 128.2265& -630.5455& -381.0930\
$dir=0$
$c$ & 0.0357& 1.2473& 0.2119&& 0.3593& -0.2755& 2.1764\
$c$ & -17.9048& -37.1111& 8.8591&& -30.7381& -9.5952& -3.0000\
$c$ & 105.5518& 232.1160& -94.7351&& 100.2497& 141.2778& -259.7326\
ottomrule
end{tabular}
end{table*}
其中multicolumn{3}{c}{text}
是一种常用的合并多列并居中的方法,依次为基础,如果想把Table 1改成显示表格边界线,按照以往的套路,我们把:
egin{tabular}{rrrrcrrrc}
修改成:
egin{tabular}{|r|r|r|r|c|r|r|r|c|}
结果却成了Table 2的样式:
啊?这么丑,绝对不是我想要的!
于是再改:
% Table 3
egin{table*}centering
caption{Caption}
a{1.2}
egin{tabular}{|r|r|r|r|r|r|r|}hline
& multicolumn{3}{c|}{$w = 8$}& multicolumn{3}{c|}{$w = 16$} \
cline{2-4} cline{5-7}
& $t=0$ & $t=1$ & $t=2$ & $t=0$ & $t=1$ & $t=2$ \ hline hline
$dir=1$ & & & & & &\
$c$ & 0.0790 & 0.1692 & 0.2945 & 0.3670 & 0.7187 & 3.1815\
$c$ & -0.8651& 50.0476& 5.9384& -9.0714& 297.0923& 46.\
$c$ & 124.2756& -50.9612& -14.2721& 128.2265& -630.5455& -381.0930\
$dir=0$ & & & & & &\
$c$ & 0.0357& 1.2473& 0.2119& 0.3593& -0.2755& 2.1764\
$c$ & -17.9048& -37.1111& 8.8591& -30.7381& -9.5952& -3.0000\
$c$ & 105.5518& 232.1160& -94.7351& 100.2497& 141.2778& -259.7326\
hline
end{tabular}
end{table*}
这里要留意multicolumn{3}{c|}{$w = 8$}
中的c|
,虽然在egin{tabular}{|r|r|r|r|r|r|r|}
定义了表格边界,但是由于multicolumn
的使用,在右边界上的规则在此处不再成立,因此需要再次声明右边界,而不声明就是Table 4的样子: