15

Whenever I use the colortbl package to format tables, a thin white space between the cells sometimes shows up on screen (not in print for as far as I can tell). For example in this table:

Is there an easy way to enlarge each rectangle by a tiny amount so that the white space is not visible anymore?

(My guess is that the white space appears due to rounding in my pdf viewer, evince. I don't know if other pdf viewers have the same issue. Regardless, I would like to have my pdf file look good in common pdf readers)

2 Answers 2

14

Yes this is due to the coloured panels being snapped to pixel boundaries.

You can go \\\noalign{\vskip-0.1pt} for a suitably small amount between each row, then the panels will overlap and you are less likely to get a gap. You can add set \extrarowheight to something large to compensate (which is probably a good idea anyway, to keep the capital letters away from the top of the panels)

That is for horizontal lines. For vertical lines \rowcolor has optional arguments to specify optional left and right overhang.

4
  • 1
    Awesome, works like a charm! Maybe this could be default behavior of colortbl?
    – yori
    Commented Apr 27, 2012 at 14:51
  • 2
    Can't really make it the default, it's inherent in the way TeX handles color really, a "small" overlap between tow large panels isn't noticeable but if you have a 0.4pt \hline between them overlapping by 0.1pt is probably too much. You can get the same behaviour without colortbl just use something like \fcolorbox Tex will specify that the coloured panel and the border are adjacent but some viewers my snap them apart by a pixel. Commented Apr 27, 2012 at 15:43
  • 2
    I see. Perhaps a length parameter could be added to the colortbl package, which can be set by the user to enlarge each background by a small overlap?
    – yori
    Commented Apr 27, 2012 at 16:32
  • 1
    yes that's a possibility, I'll think about it... Commented Apr 27, 2012 at 18:33
1

The package nicematrix provides tools specially designed to solve that problem. The output is perfect in all the PDF viewers, at all levels of zoom.

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

\begin{document}
\begin{NiceTabular}{cccwl{8cm}}
\CodeBefore
  \columncolor{gray}{1}     
  \rowcolor{gray}{1}
  \rectanglecolor{lightgray}{2-2}{2-4}
  \rectanglecolor{lightgray}{2-2}{6-2}
  \rectanglecolor{gray}{3-3}{3-4}
  \rectanglecolor{gray}{3-3}{7-3}
  \cellcolor{black}{7-2,8-2,8-3}
\Body
  & \Block[l]{1-3}{\color{white}Property 1} \\
  & & \Block[l]{1-2}{Property 2} \\
  $\blacktriangledown$ & & & \color{white}Property 3 \\
  & $\blacktriangledown$ \\
  & & $\blacktriangledown$ & \bfseries Part 1 \\
  $\bullet$ & $\bullet$ & $\bullet$ & 1. Step one \\
  \hline
  $\bullet$ & \color{white} $\bullet$ & $\bullet$ & 2. Step two \\
  \hline
  $\bullet$ & \color{white} $\bullet$ & \color{white} $\bullet$ & 3. Step three \\
  \hline
\end{NiceTabular}

\end{document}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .