单元格颜色部分覆盖单元格边框

单元格颜色部分覆盖单元格边框

我用它\cellcolor来给一些单元格添加背景。如您在屏幕截图中看到的那样,单元格颜色部分超出了单元格的边框。

在此处输入图片描述

这是我的表格的 LaTeX 代码。

\usepackage[table]{xcolor}

\begin{table}[h]
\centering
\setlength{\tabcolsep}{12pt}
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{ l l l l}
\hline
  \multicolumn{1}{|c|}{1} & \multicolumn{1}{c|}{47.5\% (52.5\%)} & \multicolumn{1}{c|}{37.4\% (41.3\%)} & \multicolumn{1}{c|}{26.8\% (29.6\%)} \\
  \multicolumn{1}{|c|}{2} & \multicolumn{1}{c|}{70.9\% (74.3\%)} & \multicolumn{1}{c|}{61.5\% (68.2\%)} & \multicolumn{1}{c|}{51.4\% (57.5\%)} \\
  \multicolumn{1}{|c|}{3} & \multicolumn{1}{c|}{72.1\% (76.0\%)} & \multicolumn{1}{c|}{65.4\% (69.8\%)} & \multicolumn{1}{c|}{54.7\% (59.8\%)} \\
  \multicolumn{1}{|c|}{4} & \multicolumn{1}{c|}{{\cellcolor[gray]{.9}}72.1\% (77.1\%)} & \multicolumn{1}{c|}{62.6\% (67.0\%)} & \multicolumn{1}{c|}{52.5\% (55.9\%)} \\
  \multicolumn{1}{|c|}{5} & \multicolumn{1}{c|}{70.9\% (76.0\%)} & \multicolumn{1}{c|}{60.3\% (65.4\%)} & \multicolumn{1}{c|}{51.4\% (54.2\%)} \\
\hline
\end{tabular}
\end{table}

我该如何解决这个问题?

答案1

说实话,我对此还是不太满意,因为我希望表格在任何查看器中都能很好地显示。所以我通过使用\multicolumn{1}{>{\columncolor[gray]{.9}[9pt]}c|}{72.1\% (77.1\%)}

完整代码如下:

\documentclass[12pt, a4paper]{report}
\usepackage[table]{xcolor}

\begin{document}
\begin{table}[ht]
\centering
\setlength{\tabcolsep}{12pt}
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{ l l l l}
\hline
  \multicolumn{1}{|c|}{1} & \multicolumn{1}{c|}{47.5\% (52.5\%)} & \multicolumn{1}{c|}{37.4\% (41.3\%)} & \multicolumn{1}{c|}{26.8\% (29.6\%)} \\
  \multicolumn{1}{|c|}{2} & \multicolumn{1}{c|}{70.9\% (74.3\%)} & \multicolumn{1}{c|}{61.5\% (68.2\%)} & \multicolumn{1}{c|}{51.4\% (57.5\%)} \\
  \multicolumn{1}{|c|}{3} & \multicolumn{1}{c|}{72.1\% (76.0\%)} & \multicolumn{1}{c|}{65.4\% (69.8\%)} & \multicolumn{1}{c|}{54.7\% (59.8\%)} \\
  \multicolumn{1}{|c|}{4} & \multicolumn{1}{>{\columncolor[gray]{.9}[9pt]}c|}{72.1\% (77.1\%)} & \multicolumn{1}{c|}{62.6\% (67.0\%)} & \multicolumn{1}{c|}{52.5\% (55.9\%)} \\
  \multicolumn{1}{|c|}{5} & \multicolumn{1}{c|}{70.9\% (76.0\%)} & \multicolumn{1}{c|}{60.3\% (65.4\%)} & \multicolumn{1}{c|}{51.4\% (54.2\%)} \\
\hline
\end{tabular}
\end{table}
\end{document}

为了达成这个:在此处输入图片描述

我对结果很满意。也许对其他人也有用。

相关内容