# hhline and cell color problems revisited

So, I've read a lot of issues with cell coloring and cell border. I tried to fix them as follows:

I use hhline to print horizontal cell borders.

If I am in the middle of a multirow cell, I print hhline using the same color as the cell. This avoids having white lines in the middle.

However, I still get pale lines running through the middle of my multirow cell. They aren't white, but they are a paler color than the cell.

Here is a MWE.

\documentclass[]{article}

\usepackage{array}
\usepackage{tabularx}
\usepackage{siunitx}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{hhline}

\begin{document}

\begin{tabularx}{1\textwidth}{m{0.333\textwidth} m{0.333\textwidth} m{0.333\textwidth} }

\hhline{---}
\multicolumn{1}{|c|}{\cellcolor[RGB]{255, 255, 0} a cell} &
\multicolumn{1}{c|}{\cellcolor[RGB]{255, 192, 203} middle} &
\multicolumn{1}{c|}{right cell} \tabularnewline

\hhline{|-|-|-|}

\multicolumn{1}{|c|}{\cellcolor[RGB]{255, 255, 0} a cell} &
\multicolumn{2}{c|}{\cellcolor[RGB]{255, 165, 0} } \tabularnewline

\hhline{|-|>{\arrayrulecolor[RGB]{255, 165, 0}}-->{\arrayrulecolor{black}}|}

\multicolumn{1}{|c|}{\cellcolor[RGB]{255, 255, 0} a cell} &
\multicolumn{2}{c|}{\multirow{-2}{*}{\cellcolor[RGB]{255, 165, 0} multirow cell with pale line through the middle}} \tabularnewline

\hhline{|-|--|}

\end{tabularx}

\end{document}


Is this just a problem of my particular pdf viewer? Is there a simple fix?

You get this sort of lines when two colored surfaces touch exactly. And the only way to get rid of them is either to ensure that the surfaces overlap a bit, to paint over the gap, or to have only one surface:

\documentclass[]{article}
\usepackage[table]{xcolor}
\usepackage{tikz}

\begin{document}

{\color{red}\rule{1cm}{1cm}\rule{1cm}{1cm}}

{\color{red}\rule{1cm}{1cm}\hspace{-0.1pt}\rule{1cm}{1cm}}

{\color{red}\rule{1cm}{1cm}\rule{1cm}{1cm}\tikz[overlay]\draw(-1,0)--++(0,1);}

{\color{red}\rule{2cm}{1cm}}

\end{document}


Using \hhline imho doesn't help much as you then have the gaps between the lines and the colored cell. But you can e.g. move the second line a bit up:

\documentclass[]{article}
\usepackage{array}
\usepackage{tabularx}
\usepackage{siunitx}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{hhline,tikz}

\begin{document}

\begin{tabularx}{1\textwidth}{m{0.333\textwidth} m{0.333\textwidth} m{0.333\textwidth} }

\hhline{---}
\multicolumn{1}{|c|}{\cellcolor[RGB]{255, 255, 0} a cell} &
\multicolumn{1}{c|}{\cellcolor[RGB]{255, 192, 203} middle} &
\multicolumn{1}{c|}{right cell} \tabularnewline

\hhline{|-|-|-|}

\multicolumn{1}{|c|}{\cellcolor[RGB]{255, 255, 0} a cell} &
\multicolumn{2}{c|}{\cellcolor[RGB]{255, 165, 0} }
\tabularnewline[-0.5pt] % a a bit up.

\multicolumn{1}{|c|}{\cellcolor[RGB]{255, 255, 0} a cell} &
\multicolumn{2}{c|}{\multirow{-2}{*}{\cellcolor[RGB]{255, 165, 0}multirow cell with pale line through the middle}} \tabularnewline

\hhline{|-|--|}

\end{tabularx}

\end{document}


• I do not understand this part of table \tabularnewline \\[\dimexpr-\normalbaselineskip -0.5pt\relax] % a a bit up.. Is it sufficient just \tabularnewline? – Zarko Feb 27 '17 at 15:07
• @Zarko Sorry this was a remnant of tests with the \hhline in between. Without it one naturally need only one new line. – Ulrike Fischer Feb 27 '17 at 15:11

Some PDF viewers (eg SumatraPDF which uses MuPDF) draw a thin white line between two adjacent colored rectangles with the same color. This phenomenon occurs when the rectangles are drawn in two different instructions fill in the PDF stream (the operator fill of PostScript is in fact coded by a f in the PDF streams). If the rectangles are drawn by the same instruction fill, no thin white line is displayed.

The package nicematrix provides tools to avoid that problem (and other linked to the display of rules in the tabulars).

Consider the following code:

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{ccc}[code-before = {\rowcolor{red!15}{1,2,3}}]
A & B & C \\
A & B & C \\
A & B & C \\
A & B & C \\
\end{NiceTabular}

\end{document}


In the resulting PDF (after uncompression of the streams), we have the following code:

0.0 26.40134 57.58482 -11.95532 re
0.0 14.44601 57.58482 -11.95532 re
0.0  2.49069 57.58482 -11.95532 re
f


Each operator re (for rectangle) adds a rectangle to the current path but there is only one operator f (for fill) which fills the complete path.

No thin white line will appear in the PDF viewers, even in SumatraPDF.