# Solution for disappearing table/cell borders with \rowcolor in the PDF viewer depending on zoom?

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{--}
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:

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?

• that is known issue many time asked here. line is there, however due to pdf viewer artifact it is not visible (without magnification). of-topic, your table has error, probably is missed one column specification. May 13 '19 at 16:04
• Imho the only really stable way to solve this is to redraw the lines after the background has been drawn. I normally do this with lots of tikzmarks, see e.g. tex.stackexchange.com/a/380440/2388 and tex.stackexchange.com/a/303859/2388. May 13 '19 at 16:04

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
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...

If you are allowed to use a different table package, you can achieve the same result with cals and simple, straight forward coding:

\documentclass{article}
\usepackage{cals}
\usepackage{xcolor}

\begin{document}

\begin{calstable}[c]
% Defining columns relative to each other and relative to the margins
\colwidths{{\dimexpr(\columnwidth)/4*2\relax}
{\dimexpr(\columnwidth)/4\relax}
{\dimexpr(\columnwidth)/4\relax}
}
% The tabular fills the text area if sum of all columns is 4

% Set up the tabular
\makeatletter
\def\cals@framers@width{0.4pt}   % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0.4pt}
\def\cals@bodyrs@width{0.4pt}
\cals@setcellprevdepth{Al}
\def\cals@cs@width{0.4pt}             % Inside rules, reduce if the rule is too heavy
\def\cals@rs@width{0.4pt}
\def\cals@bgcolor{}

\def\gray{\ifx\cals@bgcolor\empty     % "Switch" to turn on and off colour
\def\cals@bgcolor{gray!50}
\else \def\cals@bgcolor{} \fi}

% R1H1
\brow
\gray\alignL\cell{\vfil Name}
\cell{\vfil RiY}\gray
\erow
%R2H2
\brow
\gray\alignL\cell{\vfil Name}
\cell{\vfil RiY}\gray
\erow
\mdseries
}
\tfoot{\lastrule\strut}
%R3B1
\brow
\alignL\cell{\vfil Test}
\alignC\cell{\vfil 123,04}
\cell{\vfil 0,9\,\%}
\erow
\makeatletter
\end{calstable}\par
\end{document}


The package nicematrix provides tools to deal with that problem.

This package provides an environment {NiceTabular} similar to {tabular} (of array). In this environment you can color cells, rows and columns with a syntax similar to colortbl (you have to use the key colortbl-like). However, this package don't use colortbl and the rules won't seem to vanish in Adobe Reader (or some other PDF viewers) when zooming in and out. You need several compilations.

However, there is no column X in {NiceTabular}. That's why, in the following code, I have computed by hand the width of the first column (in \mylength).

\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document}

\newlength{\mylength}
\setlength{\mylength}{\dimexpr \textwidth - 5cm - 4\tabcolsep - 3 \arrayrulewidth}

\begin{center}
\begin{NiceTabular}{|p{\mylength}|>{\arraybackslash}m{5cm}|}[colortbl-like]
\hline
\hline
\hline
\hline
Test & 123,04 \\
\hline
\end{NiceTabular}
\end{center}

\end{document}


In fact, in {NiceTabular}, it's also possible to draw all the rules with the key hvlines. It's also possible to specify the color of the row before the body of the array in the key code-before.

\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document}

\newlength{\mylength}
\setlength{\mylength}{\dimexpr \textwidth - 5cm - 4\tabcolsep - 3 \arrayrulewidth}

\begin{center}
\begin{NiceTabular}{p{\mylength}>{\arraybackslash}m{5cm}}%
[hvlines,code-before = \rowcolor{gray!50}{1-3}]