LaTeX Hierarchical Tables


本系列文章由 @yhl_leo 出品,转载请注明出处。
文章链接: http://blog.csdn.net/yhl_leo/article/details/52692655


简单整理一下表格中的分级表,以三线表Table 1为例:

table1

这种非常规的一行一列的结构,尤其是表头部分,每个子表头下,又细分了三个子表头,这种用法也是很常见的,实现方法如下:

% Table 1

\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\begin{table*}\centering
	\caption{Caption}
	\ra{1.2}
	\begin{tabular}{rrrrcrrrc}\toprule
		& \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\\
		\bottomrule
	\end{tabular}
\end{table*}

其中\multicolumn{3}{c}{text}是一种常用的合并多列并居中的方法,依次为基础,如果想把Table 1改成显示表格边界线,按照以往的套路,我们把:

\begin{tabular}{rrrrcrrrc}

修改成:

\begin{tabular}{|r|r|r|r|c|r|r|r|c|}

结果却成了Table 2的样式:

table2

啊?这么丑,绝对不是我想要的!

于是再改:

% Table 3

\begin{table*}\centering
	\caption{Caption}
	\ra{1.2}
	\begin{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*}

table3

这里要留意\multicolumn{3}{c|}{$w = 8$}中的c|,虽然在\begin{tabular}{|r|r|r|r|r|r|r|}定义了表格边界,但是由于\multicolumn的使用,在右边界上的规则在此处不再成立,因此需要再次声明右边界,而不声明就是Table 4的样子:

table4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值