Visible lines in colored table

I'm trying to do a table with colored cells. So far the code looks like this:

     \definecolor{ao}{rgb}{0.0, 0.5, 0.0}
\definecolor{applegreen}{rgb}{0.55, 0.71, 0.0}
\definecolor{azure}{rgb}{0.0, 0.5, 1.0}
{
\rowcolors{3}{ao}{applegreen}
\begin{tabular}{ |p{2cm} p{1cm} p{1cm} p{1cm} p{1cm} p{1cm} p{1cm}| }
\hline
\rowcolor{azure} \multicolumn{7}{|c|}{Title} \\
\rowcolor{azure} & A & B & C & D & E & F\\
\hline
Row A &  &   \\
Row B &  &   \\
Row C &  &   \\
Row D &  &   \\
Row E &  &   \\
Row F &  &   \\
Row G &  &   \\
\hline
\end{tabular}
}


The problem is, even though there shouldn't be any horizontal and vertical lines, they are still slightly visible. Is there a way to fix that?

BTW. sorry for ugly colors, I'm working on it!

• Do you mean the thin horizontal white line between the first and second rows? Mar 18, 2020 at 15:15
• Yep, if you zoom in they are also visible between other rows (that's actually not a big deal), same thing for the vertical ones. Mar 18, 2020 at 15:19
• It probably is a problem of the viewer. Do they also appear on printing? Mar 18, 2020 at 15:21
• @Bernard Indeed it is! I didn't realize that could be the problem. It's definitely because of VS Code, if I run it on a different viewer it works perfectly! Thanks a lot! I feel stupid right now... whatever. I've literally just spend half an hour on googling that. Mar 18, 2020 at 15:24
• It happens from time to time there can be real problems. In this case, a solution I use is to add between the rows something like \noalign{\vskip -1pt} (the exact value may vary). Mar 18, 2020 at 15:37

The standard response here is to blame your PDF viewer and certainly if you print the document or use a different PDF viewer, or even just zoom in or out a bit with your current viewer the problem will go.

But it isn't really the fault of the viewer (I can't possibly mention who's fault it is...) Ideally the coloured row background would be a single green rectangle within the PDF, if it was generated in this way you would never get artefacts at the cell boundaries. It is possible to colour tables this way using tikz or similar to measure where the cells are and then (on a later pass of latex) draw in the backgrounds, but there is not (as far as I know) an easily packaged version of that technique that is compatible with standard LaTeX tabular markup.

colortbl is designed to fit with the existing latex tabular syntax and does not have access to rows, even with the \rowcolor command, it can only access individual cells, and so your green row is generated in the PDF by a series of adjacent green rectangles, specified by coordinates. These coordinates are very exact but a PDF renderer has to round everything to the actual pixels in the viewing device. Unless it has heuristics to detect two adjacent rectangles of the same colour (which is unlikely) each rectangle will be separately rounded to the pixel coordinates and it is possible that they round differently leaving a one or two pixel gap. There really isn't much that can be done about that without fundamentally changing the way tables are constructed.

With {NiceTabular} of nicematrix, you won't see these thin white lines. Never. The tools provided by nicematrix have been designed to avoid that problem.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{ |p{2cm} p{1cm} p{1cm} p{1cm} p{1cm} p{1cm} p{1cm}| }
\CodeBefore
\rowcolors[rgb]{3}{0.0, 0.5, 0.0}{0.55, 0.71, 0.0}
\rowcolor[rgb]{0.0, 0.5, 1.0}{1,2}
\Body
\hline
\Block{1-7}{Title} \\
& A & B & C & D & E & F\\
\hline
Row A &  &   \\
Row B &  &   \\
Row C &  &   \\
Row D &  &   \\
Row E &  &   \\
Row F &  &   \\
Row G &  &   \\
\hline
\end{NiceTabular}

\end{document}


You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).