1

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?

  • 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. – Zarko May 13 at 16:04
  • 2
    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. – Ulrike Fischer May 13 at 16:04
1

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

0

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@setpadding{Ag}
\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
\thead{\bfseries
\brow
    \gray\alignL\cell{\vfil Name}
    \alignC\cell{\vfil Premium Premium Premium}
    \cell{\vfil RiY}\gray
\erow
%R2H2
\brow
    \gray\alignL\cell{\vfil Name}
    \alignC\cell{\vfil Premium Premium Premium}
    \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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.