编译时,彩色单元格之间的线条不出现

编译时,彩色单元格之间的线条不出现

我正在编译此代码,结果得到了以下表格:

在此处输入图片描述

\begin{table}[!h]
\centering
\begin{tabular}{cc|c|c}
\toprule
                                                                                      &                                                              & \textbf{$\mathcal{J}$ fairness index}           & \textbf{TB size}                                \\
\midrule
                                                                                      & \cellcolor[HTML]{9B9B9B}{\color[HTML]{000000} $16 \times 8$} & \cellcolor[HTML]{9B9B9B}{\color[HTML]{000000} } & \cellcolor[HTML]{9B9B9B}{\color[HTML]{000000} } \\ \cline{2-4} 
                                                                                      & \cellcolor[HTML]{C0C0C0}$16 \times 4$                        & \cellcolor[HTML]{C0C0C0}                        & \cellcolor[HTML]{C0C0C0}                        \\ \cline{2-4} 
\multirow{-3}{*}{\textbf{\begin{tabular}[c]{@{}c@{}}BLIND\\ METHOD\end{tabular}}}     & \cellcolor[HTML]{EFEFEF}$4 \times 4$                         & \cellcolor[HTML]{EFEFEF}                        & \cellcolor[HTML]{EFEFEF}                        \\ \midrule
                                                                                      & \cellcolor[HTML]{9B9B9B}$16 \times 8$                        & \cellcolor[HTML]{9B9B9B}                        & \cellcolor[HTML]{9B9B9B}                        \\ \cline{2-4} 
                                                                                      & \cellcolor[HTML]{C0C0C0}$16 \times 4$                        & \cellcolor[HTML]{C0C0C0}                        & \cellcolor[HTML]{C0C0C0}                        \\ \cline{2-4} 
\multirow{-3}{*}{\textbf{\begin{tabular}[c]{@{}c@{}}TRAINING\\ METHOD\end{tabular}}}  & \cellcolor[HTML]{EFEFEF}$4 \times 4$                         & \cellcolor[HTML]{EFEFEF}                        & \cellcolor[HTML]{EFEFEF}                        \\ \midrule
                                                                                      & \cellcolor[HTML]{9B9B9B}$16 \times 8$                        & \cellcolor[HTML]{9B9B9B}                        & \cellcolor[HTML]{9B9B9B}                        \\ \cline{2-4} 
                                                                                      & \cellcolor[HTML]{C0C0C0}$16 \times 4$                        & \cellcolor[HTML]{C0C0C0}                        & \cellcolor[HTML]{C0C0C0}                        \\ \cline{2-4} 
\multirow{-3}{*}{\textbf{\begin{tabular}[c]{@{}c@{}}HEURISTIC\\ METHOD\end{tabular}}} & \cellcolor[HTML]{EFEFEF}$4 \times 4$                         & \cellcolor[HTML]{EFEFEF}                        & \cellcolor[HTML]{EFEFEF}                        \\ \bottomrule
\end{tabular}
\caption{•}
\label{tab_fairness_los}
\end{table}

我想知道如何让彩色单元格之间的线条显示出来?有什么想法吗?代码中有什么问题吗?我需要一个特定的包吗?

如果我使用\hline它,\cline则会发生以下情况:在此处输入图片描述 说实话我不知道该怎么写

答案1

只需使用包hhline(添加\usepackage{hhline})并使用\hhline{~-|-|-}代替您的。在包(在您的终端上使用)\cline{2-4}的文档中,您可以找到:对于无行和对于列中的一行...hhlinetexdoc hhline~-

但只是一句:你为​​什么使用线条和彩色单元格?你的彩色单元格很好地标记了你想要的东西,你真的不需要这里的表格中的线条。好的表格排版的原则是尽量少用。首先不要用垂直线...

完整的 MWE:

\documentclass{scrartcl}

\usepackage{hhline}
\usepackage{booktabs}
\usepackage[table,xcdraw]{xcolor}
\usepackage{multirow}

\begin{document}

\begin{table}
\centering
\begin{tabular}{cc|c|c}
\toprule
                                                                                      &                                                              & \textbf{$\mathcal{J}$ fairness index}           & \textbf{TB size}                                \\
\midrule
                                                                                      & \cellcolor[HTML]{9B9B9B}{\color[HTML]{000000} $16 \times 8$} & \cellcolor[HTML]{9B9B9B}{\color[HTML]{000000} } & \cellcolor[HTML]{9B9B9B}{\color[HTML]{000000} } \\ \hhline{~-|-|-} 
                                                                                      & \cellcolor[HTML]{C0C0C0}$16 \times 4$                        & \cellcolor[HTML]{C0C0C0}                        & \cellcolor[HTML]{C0C0C0}                        \\ \hhline{~-|-|-} 
\multirow{-3}{*}{\textbf{\begin{tabular}[c]{@{}c@{}}BLIND\\ METHOD\end{tabular}}}     & \cellcolor[HTML]{EFEFEF}$4 \times 4$                         & \cellcolor[HTML]{EFEFEF}                        & \cellcolor[HTML]{EFEFEF}                        \\ \midrule
                                                                                      & \cellcolor[HTML]{9B9B9B}$16 \times 8$                        & \cellcolor[HTML]{9B9B9B}                        & \cellcolor[HTML]{9B9B9B}                        \\ \hhline{~-|-|-} 
                                                                                      & \cellcolor[HTML]{C0C0C0}$16 \times 4$                        & \cellcolor[HTML]{C0C0C0}                        & \cellcolor[HTML]{C0C0C0}                        \\ \hhline{~-|-|-} 
\multirow{-3}{*}{\textbf{\begin{tabular}[c]{@{}c@{}}TRAINING\\ METHOD\end{tabular}}}  & \cellcolor[HTML]{EFEFEF}$4 \times 4$                         & \cellcolor[HTML]{EFEFEF}                        & \cellcolor[HTML]{EFEFEF}                        \\ \midrule
                                                                                      & \cellcolor[HTML]{9B9B9B}$16 \times 8$                        & \cellcolor[HTML]{9B9B9B}                        & \cellcolor[HTML]{9B9B9B}                        \\ \hhline{~-|-|-} 
                                                                                      & \cellcolor[HTML]{C0C0C0}$16 \times 4$                        & \cellcolor[HTML]{C0C0C0}                        & \cellcolor[HTML]{C0C0C0}                        \\ \hhline{~-|-|-} 
\multirow{-3}{*}{\textbf{\begin{tabular}[c]{@{}c@{}}HEURISTIC\\ METHOD\end{tabular}}} & \cellcolor[HTML]{EFEFEF}$4 \times 4$                         & \cellcolor[HTML]{EFEFEF}                        & \cellcolor[HTML]{EFEFEF}                        \\ \bottomrule
\end{tabular}
\caption{•}
\label{tab_fairness_los}
\end{table}

\end{document}

结果:

在此处输入图片描述

答案2

这是一个解决方案,具有简化的代码,感谢软件包 makecell,它允许在单元格中换行并采用常见的格式。

此外,booktabs由于其规则的垂直填充,会在彩色行中产生白色条纹。因此,我建议改用小包boldline(来自shipunov包),并在包的上方和下方添加一些垂直填充cellspace

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{bm}
\usepackage{multirow, booktabs}
\usepackage{hhline, boldline, makecell}
\renewcommand\cellset{\bfseries}
\usepackage[table]{xcolor}
\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{3pt}

\begin{document}

\begin{table}[!h]
\centering
\begin{tabular}{cSc|Sc|c}
\hlineB{2.4}%
& &$\bm{\mathcal{J}}$ \textbf{fairness index} & \textbf{TB size} \\
\hlineB{1.5}%
& \cellcolor[HTML]{9B9B9B}{\color[HTML]{000000} $16 \times 8$} & \cellcolor[HTML]{9B9B9B}{\color[HTML]{000000} } & \cellcolor[HTML]{9B9B9B}{\color[HTML]{000000} } \\
\hhline{~---} %
& \cellcolor[HTML]{C0C0C0}$16 \times 4$ & \cellcolor[HTML]{C0C0C0} & \cellcolor[HTML]{C0C0C0}\\
\hhline{~---} %
\multirowcell{-3}{BLIND\\ METHOD}& \cellcolor[HTML]{EFEFEF}$4 \times 4$ & \cellcolor[HTML]{EFEFEF} & \cellcolor[HTML]{EFEFEF} \\
\hlineB{1.5}%
& \cellcolor[HTML]{9B9B9B}$16 \times 8$ & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B}\\
\hhline{~---} %
& \cellcolor[HTML]{C0C0C0}$16 \times 4$ & \cellcolor[HTML]{C0C0C0} & \cellcolor[HTML]{C0C0C0}\\
\hhline{~---} %
\multirowcell{-3}{TRAINING\\ METHOD} & \cellcolor[HTML]{EFEFEF}$4 \times 4$ & \cellcolor[HTML]{EFEFEF} & \cellcolor[HTML]{EFEFEF} \\
\hlineB{1.5}%\midrule
& \cellcolor[HTML]{9B9B9B}$16 \times 8$ & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B}\\
\hhline{~---} %
& \cellcolor[HTML]{C0C0C0}$16 \times 4$ & \cellcolor[HTML]{C0C0C0} & \cellcolor[HTML]{C0C0C0}\\
\hhline{~---} %
\multirowcell{-3}{HEURISTIC\\ METHOD} & \cellcolor[HTML]{EFEFEF}$4 \times 4$ & \cellcolor[HTML]{EFEFEF} & \cellcolor[HTML]{EFEFEF} \\
\hlineB{2.4}
\end{tabular}
\caption{•}
\label{tab_fairness_los}
\end{table}

\end{document} 

在此处输入图片描述

相关内容