When using \cellcolor or \rowcolor to shade a cell (or row of cells) in a table, the vertical and horizontal separators become randomly obscured or hidden when viewing the PDF. This is true for Chrome, Acrobat, and TexStudio's built-in PDF viewer.
I am required to comply with a style guide, and am allowed to use Word (!) or Tex, but the product must be a PDF. The style guide was given in Word, with a table with a shaded top row of cells. I am attempting to re-create this with LaTeX, but the PDF never renders well. The vertical and top horizontal bars around the shaded cells appear and disappear depending on zoom level. For example, see the images below, from three different zoom levels:
Zoom level 1:
Zoom level 2:
Zoom level 3:
After searching online and seeing several other posts about this, I employed and compiled many of them into this MWE. Zero of the six options work or render consistently across all zoom levels.
I have tried: tabular, tabularx, using a hack via a one-column "multicolumn," hhline, etc. Please see the MWE code below.
If anyone has an idea of how to shade a cell in a table without these rendering issues, please help!
MWE:
\documentclass[twocolumn]{article}
\usepackage{lipsum,tabularx,booktabs,tabularx,hhline}
\usepackage[table]{xcolor}
%opening
\begin{document}
Acrobat, Chrome, and TexStudio's native PDF viewer have issues showing the
vertical bars between and above cells which specify either cell color or row
color. Example tables follow:
\begin{table}
\centering\setlength{\aboverulesep}{0pt}\setlength{\belowrulesep}{0pt}
\setlength{\extrarowheight}{2pt}
\caption{As can be seen, the vertical bars between X, Y, and Z are
invisible depending on the level of zoom. The horizontal bar above is also
invisible, depending on zoom.}
\begin{tabular}{|l|l|l|}
\toprule
\rowcolor[gray]{0.85}
X & Y & Z \\
\midrule
0 & 1 & 2\\\hline
0.1 & 0.2 & 0.3\\
\bottomrule
\end{tabular}
\end{table}
\begin{table}
\centering
\caption{TabularX and the X column type do not help, though this is what I
need to use. Both toprule and hline exhibit this behavior, regarding the
top line.}
\begin{tabularx}{\columnwidth}{|X|X|X|}
\hline
\rowcolor[gray]{0.85}
X & Y & Z \\\hline
0 & 1 & 2\\\hline
0.1 & 0.2 & 0.3\\\hline
\end{tabularx}
\end{table}
\begin{table}
\centering
\caption{Multicolumn doesn't help either.}
\begin{tabularx}{\columnwidth}{|X|X|X|}
\hline
\rowcolor[gray]{0.85}
\multicolumn{1}{|X|}{X} & Y & Z \\\hline
0 & 1 & 2\\\hline
0.1 & 0.2 & 0.3\\\hline
\end{tabularx}
\end{table}
\begin{table}
\centering
\caption{hhline is also ineffective at treating this issue.}
\begin{tabularx}{\columnwidth}{|X|X|X|}
\hhline{---}
\rowcolor[gray]{0.85}
\multicolumn{1}{|X|}{X} & Y & Z \\\hhline{---}
0 & 1 & 2\\\hhline{---}
0.1 & 0.2 & 0.3\\\hhline{---}
\end{tabularx}
\end{table}
\begin{table}
\centering
\caption{hhline does not help in regular tabular mode either.}
\begin{tabular}{|l|l|l|}
\hhline{---}
\rowcolor[gray]{0.85}
X & Y & Z \\\hhline{---}
0 & 1 & 2\\\hhline{---}
0.1 & 0.2 & 0.3\\\hhline{---}
\end{tabular}
\end{table}
\begin{table}[tbph]
\centering
\caption{Just to be clear, rowcolor and cellcolor have the same issue, and
specifying vertical bars with hhline does not help. Another post suggested
putting cellcolor in brackets, which seemed pointless, but I tried. It was
indeed pointless.}
\begin{tabularx}{\columnwidth}{|X|X|X|}
\hhline{|-|-|-|}
{\cellcolor[gray]{.87}}X & {\cellcolor[gray]{.87}}Y &
{\cellcolor[gray]{.87}}Z\tabularnewline\hhline{|-|-|-|}
0 & 1 & 2\\\hhline{---}
0.1 & 0.2 & 0.3\\\hhline{---}
\end{tabularx}
\end{table}
\end{document}





calstablea try (examples: https://tex.stackexchange.com/a/530849/134144 and https://tex.stackexchange.com/a/496788/134144) or, depending on the contents of your table, a tikz matrix could also work (example: https://tex.stackexchange.com/a/497080/134144) – leandriis May 05 '20 at 17:29nicematrixwhich tries to solve that problem. If you want, I can send you this beta version and you will test it. If you agree, send me a mail (you will find my address in the documentation ofnicematrix). – F. Pantigny May 06 '20 at 12:51