tabularx、booktabs 環境中不連續的垂直虛線

tabularx、booktabs 環境中不連續的垂直虛線

我有一個非常大的表格,其中包含 4 種不同方法的結果,我的主管建議我使用垂直線來分隔方法以提高可讀性。但是,當我使用垂直虛線時,它們不是連續的,據我所知,這是 booktabs 環境中的一個非常常見的問題。一般來說,建議的解決方案是不使用垂直線,但我想使用它。有什麼解決方法嗎?我也歡迎您提出提高可讀性的建議。

這是工作範例。抱歉,這些列名稱毫無意義。

\documentclass[journal]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage{amsmath} % assumes amsmath package installed
\usepackage{amssymb} 
\usepackage{caption}
\usepackage{tabularx, booktabs}

\usepackage{arydshln}


\begin{document}

\begin{table*}
\caption{a $\rightarrow$ b}
\label{tabAB}
\begin{tabularx}{\textwidth}{@{\extracolsep{\fill}}ccc:cccc:cccc:cccc}
\toprule
 & \multicolumn{2}{c}{\begin{tabular}[c]{@{}c@{}}a \\ b \end{tabular}} & \multicolumn{4}{c}{\begin{tabular}[c]{@{}c@{}}c \\$\downarrow$\\ d \end{tabular}} & \multicolumn{4}{c}{\begin{tabular}[c]{@{}c@{}}e \\ $\downarrow$\\ f \end{tabular}} & \multicolumn{4}{c}{\begin{tabular}[c]{@{}c@{}}g \\ $\downarrow$\\ h \end{tabular}}\\ 
& & & \multicolumn{2}{c}{q} & \multicolumn{2}{c}{w} & \multicolumn{2}{c}{e} & \multicolumn{2}{c}{r} & \multicolumn{2}{c}{t} & \multicolumn{2}{c}{y}\\
\cmidrule(lr){2-15}
 & u & w & \begin{tabular}[c]{@{}c@{}}a\\ b \end{tabular} & \begin{tabular}[c]{@{}c@{}}c.\\ d \end{tabular} & \begin{tabular}[c]{@{}c@{}}e.\\ f \end{tabular} & \begin{tabular}[c]{@{}c@{}}h.\\ g \end{tabular} & \begin{tabular}[c]{@{}c@{}}j.\\ j \end{tabular}  & \begin{tabular}[c]{@{}c@{}}k.\\ t \end{tabular} & \begin{tabular}[c]{@{}c@{}}y.\\ v \end{tabular} & \begin{tabular}[c]{@{}c@{}}z.\\ w \end{tabular} & \begin{tabular}[c]{@{}c@{}}q.\\ w \end{tabular} & \begin{tabular}[c]{@{}c@{}}a.\\ t \end{tabular} & \begin{tabular}[c]{@{}c@{}}y.\\ u \end{tabular} & \begin{tabular}[c]{@{}c@{}}z.\\ x \end{tabular} \\ \hline\\
\begin{tabular}[c]{@{}c@{}}q\\ a No \\\ t \end{tabular} & & \multicolumn{13}{c}{err(\%)} \\
\cmidrule(lr){2-15}
1        & 1.33  & 1.10 & 2.43 & 1.92 & 1.57 & 1.79 & 1.58  & 1.57 & 1.19 & 1.77 & 1.42 & 1.41 & 1.89 & \textbf{1.52} \\
2        & 2.48  & 2.53 & 2.60 & 2.31 & 2.82 & 2.80 & 2.84  & 2.82 & 2.50 & 2.79 & 2.60 & 2.59 & 2.13 & \textbf{2.51} \\
3        & 2.94  & 2.75 & 2.90 & 2.46 & 4.82 & 3.48 & 2.83  & 4.82 & 2.30 & 2.45 & 3.78 & 2.77 & 2.41 & \textbf{2.67} \\
4        & 3.36  & 3.53 & 3.45 & 0.54 & 9.69 & 2.34 & 2.70  & 2.68 & 2.17 & \textbf{2.28} & 3.53 & 3.52 & 2.03 & 2.30 \\
5        & \textbf{2.38}  & 2.65 & 3.60 & 2.32 & 2.31 & 2.10 & 2.34  & 2.31 & 4.92 & 2.05 & 2.81 & 2.78 & 2.08 & 2.33 \\\\
Overall        & 2.90  & 2.11 &  2.80 & 2.11 & 2.84 & 2.30 & 3.86  & 3.84 & 2.02 & 2.27 & 2.23 & 3.21 & 2.51 & \textbf{2.87} \\\\
\begin{tabular}[c]{@{}c@{}}t\\ w \end{tabular} & \textbf{1.55} & 1.88 & 2.09 & 1.59 & 1.15 & 1.01 & 1.15 & 1.15 & 1.64 & 1.98 & 1.85 & 1.85 & 1.24 & 1.68 \\
\bottomrule

\end{tabularx}
\end{table*}

\end{document}

不同意。

虛線應從第一行延續到末尾。

答案1

這是一個不需要垂直線(虛線或連續線)的解決方案。它透過\cmidrule在標題材料中明智地放置指令來提供更多結構來實現這一點。它也從 a 環境切換tabularx到 atabular*環境;進行此切換是因為似乎不需要在儲存格內自動換行。

在此輸入影像描述

\documentclass[journal]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,caption,booktabs}
%% Handy shortcut macro:
\newcommand\mytab[1]{\begin{tabular}[c]{@{}c@{}} #1 \end{tabular}}

\begin{document}

\begin{table*}
\caption{a$\to$b} \label{tabAB}
\setlength\tabcolsep{0pt} % let LaTeX figure out intecol. whitespace
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} *{15}{c} }
\toprule
 \mytab{q\\a No\\t} 
 & \multicolumn{2}{c}{\mytab{a\\$\downarrow$\\ b}} 
 & \multicolumn{4}{c}{\mytab{c\\$\downarrow$\\ d}}  
 & \multicolumn{4}{c}{\mytab{e\\$\downarrow$\\ f}}
 & \multicolumn{4}{c}{\mytab{g\\$\downarrow$\\ h}}\\ 
\cmidrule{4-7} \cmidrule{8-11} \cmidrule{12-15} 
& & & \multicolumn{2}{c}{q} & \multicolumn{2}{c}{w} 
    & \multicolumn{2}{c}{e} & \multicolumn{2}{c}{r} 
    & \multicolumn{2}{c}{t} & \multicolumn{2}{c}{y}\\
\cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9} 
\cmidrule{10-11} \cmidrule{12-13} \cmidrule{14-15} 
 & u & w 
 & \mytab{a\\b} & \mytab{c.\\d} & \mytab{e.\\f} & \mytab{h.\\g} 
 & \mytab{j.\\j}& \mytab{k.\\t} & \mytab{y.\\v} & \mytab{z.\\w} 
 & \mytab{q.\\w}& \mytab{a.\\t} & \mytab{y.\\u} & \mytab{z.\\x}\\
\midrule
 & \multicolumn{14}{c}{err(\%)} \\
\cmidrule{2-15}
1  & 1.33  & 1.10 & 2.43 & 1.92 & 1.57 & 1.79 & 1.58  & 1.57 
   & 1.19 & 1.77 & 1.42 & 1.41 & 1.89 & \textbf{1.52} \\
2  & 2.48  & 2.53 & 2.60 & 2.31 & 2.82 & 2.80 & 2.84  & 2.82 
   & 2.50 & 2.79 & 2.60 & 2.59 & 2.13 & \textbf{2.51} \\
3  & 2.94  & 2.75 & 2.90 & 2.46 & 4.82 & 3.48 & 2.83  & 4.82 
   & 2.30 & 2.45 & 3.78 & 2.77 & 2.41 & \textbf{2.67} \\
4  & 3.36  & 3.53 & 3.45 & 0.54 & 9.69 & 2.34 & 2.70  & 2.68 
   & 2.17 & \textbf{2.28} & 3.53 & 3.52 & 2.03 & 2.30 \\
5  & \textbf{2.38}  & 2.65 & 3.60 & 2.32 & 2.31 & 2.10 & 2.34  
   & 2.31 & 4.92 & 2.05 & 2.81 & 2.78 & 2.08 & 2.33 \\[1ex]
Overall  & 2.90  & 2.11 &  2.80 & 2.11 & 2.84 & 2.30 & 3.86  
   & 3.84 & 2.02 & 2.27 & 2.23 & 3.21 & 2.51 & \textbf{2.87} \\[1ex]
\mytab{t\\w} & \textbf{1.55} & 1.88 & 2.09 & 1.59 & 1.15 & 1.01 & 1.15 
   & 1.15 & 1.64 & 1.98 & 1.85 & 1.85 & 1.24 & 1.68 \\
\bottomrule
\end{tabular*}
\end{table*}

\end{document}

相關內容