3

I am using \cellcolor to give a background to some cells. The cell color is partially coming over the border of the cell as you can see in the screenshot.

enter image description here

This is my LaTeX code for the table.

\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}

How could I solve this?

6
  • What does it look like when you zoom into the apparent overlap? Does it go away?
    – Werner
    Sep 10, 2013 at 21:04
  • yes it does go away, but it ain't nice when you see it at 100%
    – Krt_Malta
    Sep 10, 2013 at 21:05
  • Readers tend to render the output based on the zoom-level. And, these renderings are pixel-based. In some instances, the lines (horizontal or vertical) could disappear. That's just how it is. And it may differ from one reader to another.
    – Werner
    Sep 10, 2013 at 21:07
  • 1
    Please always post complete documents (not just fragments) If I try your document It works with xpdf and acrobat reader, but some of viewers have problems with such constructs. As described in the color package documentation you can try increasing the length \arrayrulewidth to make it less likely they get dropped. (perhaps its just your test example, but why use multicolumn on every entry?) Also, but unrelated never use [h] use at least [ht] Sep 10, 2013 at 21:12
  • I use multicolumn on every entry because I don't manage to center align the cells in any other way. Do you know how I can do this without multicolumn?
    – Krt_Malta
    Sep 10, 2013 at 21:21

1 Answer 1

8

For the record, I still wasn't happy with this since I wanted the table to appear well in any viewer. So I sort of went round the problem by using \multicolumn{1}{>{\columncolor[gray]{.9}[9pt]}c|}{72.1\% (77.1\%)}

So the full code is:

\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}

to achieve this: enter image description here

I'm happy with the result. Maybe it would be useful to someone else.

Not the answer you're looking for? Browse other questions tagged .