[Tex/LaTex] Solution for disappearing table/cell borders with \rowcolor in the PDF viewer depending on zoom

cellcolorcolortblhlinerowcolortables

We are currently trying to convert some documents (with our corporate design) from InDesign to LaTeX. These documents are supposed to be available on the Homepage as PDF and also print out nicely.
The problem is they contain tables with colored cells and border lines all around.

Now, the cell borders of colored cells disappear in the PDF viewer (Adobe Acrobat) depending on the zoom size. This is a known problem, but I have not found any solution that would fix the display in the PDF viewer. Mostly, the comments/solutions found here are that the document will print out nicely anyway, so it's no big deal. Unfortunately, as the documents are mainly supposed to be viewed online, this is indeed a big deal for us and makes our documents look quite unprofessional.

Here is a MWE:

\documentclass{article}

\usepackage{tabularx}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{hhline}

\newcommand\Tstrut{\rule{0pt}{2.7ex}} 
\newcommand\Bstrut{\rule[-1.4ex]{0pt}{0pt}}

\begin{document}
%\setlength\arrayrulewidth{0.66pt}

\newcolumntype{A}{>{\raggedright\Tstrut}X<{\Bstrut}}
\newcolumntype{B}{>{\centering\arraybackslash\Tstrut}m{3cm}<{\Bstrut}}

\begin{tabularx}{\textwidth}{|A|B|}\hhline{--}
\rowcolor{gray!50}\textbf{Name} & \textbf{Premium Premium Pr}  \\\hhline{--}
\rowcolor{gray!50}\textbf{Name} & \textbf{Premium Premium Pr}  \\\hline
\rowcolor{gray!50}\textbf{Name} & \textbf{Premium Premium Pr}  \\\hline
Test & 123,04 & 0,9\,\% \\\hline
\end{tabularx}

\end{document}

When viewed in SumatraPDF, all lines are visible, but the PDF viewer on most customer's computers will be Acrobat. There, the lines disappear depending on the zoom level:
enter image description here
enter image description here
enter image description here

It looks as if the cell coloring of the right / lower cell is drawn after the line and due to rounding differences overwrites the line. Increasing \arrayrulewidth did not really solve the issue, as the lines will still disappear.

This is no problem of Acrobat in general, because the documents generated in InDesign perfectly show the cell borders even with very small zoom (https://www.generali.at/privatkunden/vorsorge-vermoegen/kundeninformationsdokumente/basisinformationsblaetter/)

What are possible workarounds to make the lines always appear in the PDF viewer and in print? Switching from \hline to \hhline did not solve the problem…

Is there any way to make the cell background a tiny amount smaller so that the rounding of Acrobat will not overprint the cell border?
Or are there any other possibilities, like forcing LaTeX to print all table borders after all backgrounds?

Best Answer

Thanks to @Ulrike-Fischer, I figured out how to print all table/cell borders after the whole table is printed (using pgfmark markers to tag all coordinates and printing the lines in a tikz overlay afterwards):

\documentclass{article}

\usepackage{tabularx}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usetikzlibrary{calc}

\newcommand\Tstrut{\rule{0pt}{2.7ex}}
\newcommand\Bstrut{\rule[-1.4ex]{0pt}{0pt}}

\begin{document}
 \setlength\arrayrulewidth{5pt}
 \setlength\tabcolsep{3pt}

\newcolumntype{A}{>{\raggedright\Tstrut}X<{\Bstrut}}
\newcolumntype{B}{>{\centering\arraybackslash\Tstrut}m{3cm}<{\Bstrut}}
\newcounter{TAB}

\newcommand{\showTable}{
\stepcounter{TAB}
\begin{tabularx}{\linewidth}{@{\pgfmark{leftTAB\theTAB}}|A@{\hspace{\tabcolsep}\pgfmark{col1TAB\theTAB}}|B|@{\pgfmark{rightTAB\theTAB}}}\noalign{\pgfmark{topTAB\theTAB}}\hline
\rowcolor{gray!50}\textbf{Name} & \textbf{Premium Premium Pr}  \\\hline\noalign{\pgfmark{row1TAB\theTAB}}
\rowcolor{gray!50}\textbf{Name} & \textbf{Premium Premium Pr}  \\\hline\noalign{\pgfmark{row2TAB\theTAB}}
\rowcolor{gray!50}\textbf{Name} & \textbf{Premium Premium Pr}  \\\hline\noalign{\pgfmark{row3TAB\theTAB}}
Test & 123,04 \\\hline
\noalign{\pgfmark{bottomTAB\theTAB}}%
\end{tabularx}%
\tikz[overlay, remember picture, line width=\arrayrulewidth, black] {
    % Horizontal Lines
    \draw ($ ({pic cs:leftTAB\theTAB} |- {pic cs:topTAB\theTAB}) + (0,-\arrayrulewidth/2) $) -- %
        ($ ({pic cs:rightTAB\theTAB} |- {pic cs:topTAB\theTAB}) + (0,-\arrayrulewidth/2) $);%
    \draw ($ ({pic cs:leftTAB\theTAB} |- {pic cs:row1TAB\theTAB}) + (0,\arrayrulewidth/2) $) -- %
        ($ ({pic cs:rightTAB\theTAB} |- {pic cs:row1TAB\theTAB}) + (0,\arrayrulewidth/2) $);%
    \draw ($ ({pic cs:leftTAB\theTAB} |- {pic cs:row2TAB\theTAB}) + (0,\arrayrulewidth/2) $) -- %
        ($ ({pic cs:rightTAB\theTAB} |- {pic cs:row2TAB\theTAB}) + (0,\arrayrulewidth/2) $);%
    \draw ($ ({pic cs:leftTAB\theTAB} |- {pic cs:row3TAB\theTAB}) + (0,\arrayrulewidth/2) $) -- %
        ($ ({pic cs:rightTAB\theTAB} |- {pic cs:row3TAB\theTAB}) + (0,\arrayrulewidth/2) $);%
    % Vertical lines: left table border, column separators, right table border
    \draw ($ ({pic cs:leftTAB\theTAB} |- {pic cs:topTAB\theTAB}) + (\arrayrulewidth/2,0) $) -- %
        ($ ({pic cs:leftTAB\theTAB} |- {pic cs:bottomTAB\theTAB}) + (\arrayrulewidth/2,0) $);%
    \draw ($ ({pic cs:col1TAB\theTAB} |- {pic cs:topTAB\theTAB}) + (\arrayrulewidth/2,0) $) -- %
        ($ ({pic cs:col1TAB\theTAB} |- {pic cs:bottomTAB\theTAB}) + (\arrayrulewidth/2,0) $);%
    \draw ($ ({pic cs:rightTAB\theTAB} |- {pic cs:topTAB\theTAB}) - (\arrayrulewidth/2,0) $) -- %
        ($ ({pic cs:rightTAB\theTAB} |- {pic cs:bottomTAB\theTAB}) - (\arrayrulewidth/2,0) $);%
}%
}

\showTable

\showTable

\showTable

\end{document}

In addition to Ulrike's posts, I also had to shift the coordinates by half an \arrayrulewidth, because \draw expects the coordinate to be the middle of the line, while the pgfmarks indicate the left/right edge.

My example also shows how to use a counter for an arbitrary number of tables that are created by LaTeX commands. The \hline are not strictly needed, but I still left them in there to see that the \tikz lines exactly overprint the \hline.

Now the table looks good with all zoom settings even in Acrobat Reader...

enter image description here

Related Question