如下面的图表和 MWE 所示,我的一些彩色表格单元格的颜色被单元格颜色遮住了。如果能帮助我解决这个问题,我将不胜感激。
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[table]{xcolor}
\makeatletter
\providecommand{\tabularnewline}{\\}
\makeatother
\usepackage{babel}
\begin{document}
\begin{tabular}{c|c|c|c|cc|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{A} & \multicolumn{1}{c}{B} & \multicolumn{1}{c}{C} & D & \multicolumn{1}{c}{E}\tabularnewline
\cline{2-6}
a & \cellcolor{blue!25} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & & \cellcolor{red!25} \tabularnewline
\cline{2-3}
b & & & \multicolumn{1}{c}{} & & \tabularnewline
\cline{2-4}
c & & & & & \tabularnewline
\cline{2-5}
d & & & & \multicolumn{1}{c|}{} & \tabularnewline
\cline{2-6}
e & & \cellcolor{green!25} & & \multicolumn{1}{c|}{} & \tabularnewline
\cline{2-6}
\end{tabular}
\end{document}
答案1
您可以使用hhline
这里只是增加了垂直空间,并没有被过度绘制\cellcolor
。
代码
\documentclass{standalone}
\usepackage[table]{xcolor}
\usepackage{hhline}
\begin{document}
\begin{tabular}{c|c|c|c|cc|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{A} & \multicolumn{1}{c}{B} & \multicolumn{1}{c}{C} & D & \multicolumn{1}{c}{E} \tabularnewline \hhline{~|*{5}{-}}
a & \cellcolor{blue!25} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & & \cellcolor{red!25} \tabularnewline \cline{2-3}
b & & & \multicolumn{1}{c}{} & & \tabularnewline \cline{2-4}
c & & & & & \tabularnewline \cline{2-5}
d & & & & \multicolumn{1}{c|}{} & \tabularnewline \hhline{~|*5-}
e & & \cellcolor{green!25} & & \multicolumn{1}{c|}{} & \tabularnewline \hhline{~|*5-}
\end{tabular}
\end{document}
输出
答案2
{NiceTabular}
该包的环境nicematrix
具有专门设计来解决此类问题的工具。
\documentclass[margin=1cm]{standalone}
\usepackage{nicematrix}
\usepackage{xcolor}
\begin{document}
\begin{NiceTabular}{ccccc}[first-row,first-col,hvlines]
\CodeBefore
\cellcolor{blue!25}{1-1}
\cellcolor{red!25}{1-5}
\cellcolor{green!25}{5-2}
\Body
& A & B & C & D & E \\
a & & \Block{1-*}{} & \Block{2-1}{} & \Block{3-1}{} & \Block{4-1}{} \\
b & & & \Block{1-*}{} \\
c & & & & \Block{1-*}{} \\
d & & & & & \Block{1-*}{} \\
e \\
\end{NiceTabular}
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。