6

In a larger project, we have trouble producing tables that look "just right" because use of colorcell leaves little vertical lines between colored cell areas. I've made a minimal table that demonstrates, as seen from this screenshot:

table with white lines between cells

We've read a lot of posts about this, do not have any definitive answers. I think I'm getting closer to a comprehensive understanding of the vertical lines issue. I'm posting LaTeX example code that demonstrates several variants. In some PDF viewers, it appears the gray area is smooth, while others still show a faint ghost of white.

In the end, I'm not able to eliminate the little white line without setting tabcolsep to 0, this seems unfortunate/heroic/incorrect.

We also have the problem that the horizontal lines sometimes also show in other tables using colortbl, but I gather that is actually a separate problem (if I'm reading this correctly: \url{Very thin white line in colortbl}). If I do get a satisfactory before/after comparison, I'll start another thread here.

Here's my best result, using the proposal at the end of this code:

enter image description here

This is a snapshot from the viewer Evince in Ubuntu Linux, to my eye there is still a faint bit of white. It looks a little different on various monitors. I've looked at this on various monitors in various OS, it appears to be a touchy PDF problem.

This is the best I can do so far, if there is a better, less tedious way to do it, I wish you'd tell me. I don't totally hate setting tabcolsep to 0, but then I do hate manually inserting indentation space just on the left side of the table. I don't care if the right side goes right up to the edge.

Please don't let your answer be "redesign your table to fit our opinion of what looks nice". This is the one the professors want to use.

In my code, I leave all of the packages we use because a smaller MWE won't necessarily reproduce the same problem the same way. The very important effect of the array package is my evidence for still loading those other things.

\documentclass[letterpaper,landscape,11pt,english]{article}
\usepackage{lmodern}
\usepackage[scaled=0.9]{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[landscape]{geometry}
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
\setlength{\parskip}{10bp}
\setlength{\parindent}{0pt}
\usepackage{array}
\usepackage{calc}
\usepackage{rotating}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{hhline}
\makeatletter

\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{ifthen}
\usepackage{moresize}
\usepackage{verbatim}

\usepackage{color}
\usepackage{colortbl}
\usepackage{adjustbox}
\usepackage{url}

\definecolor{gr}{RGB}{240,240,240}

\makeatother

\usepackage{babel}
\begin{document}
%\normalsize{}

Paul Johnson

March 26, 2016

We have fought a battle with coloring in LaTeX tables.  The problem is
that when one colors a cell, one either obliterates the lines of the
border or one is unable to get the line colors correctly.  The
ordinary line drawing functions like \\hline and \\cline are not
comfortable with colored cells, one is urged to change to hhline to
draw the lines. With hhlines, the colors of the cell backgrounds do not
destroy the border lines. But there's a new problem, the accidental
white line border.

The trouble case for this is illustrated in the first table, where you
should see tiny white vertical lines between the cells of the colored     row.

% Am using guide in "colortbl.pdf" to use hhline to adjust color of
% column separator. However, it appears tabular* just ignores this

\setlength\tabcolsep{0pt}
\begin{tabular*}{11cm}{@{\extracolsep{\fill}}>{\centering}p{2.1cm}|>    {\centering}m{2.9cm}|>{\centering}m{3cm}|>{\centering}m{2.9cm}|}
\multicolumn{4}{c}{\textbf{A Frustrating Table with white lines}}\tabularnewline
\hhline{~---}
 & \multicolumn{1}{>{\centering}m{2.9cm}}{{\cellcolor{gr}}Here's a box\\
 Score}& \multicolumn{1}{>{\centering}m{3cm}}{{\cellcolor{gr}}Another
         Box with two\\
 Rows} &{\cellcolor{gr}}Student's\\
 Proficiency Level\tabularnewline
\hhline{----} 
\multicolumn{1}{|>{\centering}p{2.1cm}|}{Science} & 28 & 26 or above &     Proficient\tabularnewline
\hline 
\end{tabular*}

Those are not actually white lines. They are more correctly described     as the absence of gray lines.

Study this:

\url{https://tex.stackexchange.com/questions/65604/hhline-adds-white-    line-where-no-line-is-intended}

The white line is the absence of a line caused by my use
of hhline, but I don't see how to change the color of that one little
line.

Here I try to set the row color as gray, but place the 
first cell as    white. 

But the white lines show unless we tune up the rowcolor overlap, 
which puts some gray outside the table on the right

\setlength\tabcolsep{0pt}
\begin{tabular*}{11cm}{@{\extracolsep{\fill}}
>{\centering}p{2.1cm}|
>{\centering}m{2.9cm}|
>{\centering}m{3cm}|
>{\centering}m{2.9cm}|}
\multicolumn{4}{c}{\textbf{A Frustrating Table with white
 lines}}\tabularnewline
\hhline{~---}
\rowcolor{gr}[0mm][1mm]
\multicolumn{1}{>{\centering}m{2.1pt}|}{\cellcolor{white}}
 & \multicolumn{1}{>{\centering}m{2.9cm}}{Here's a box\\
 Score}& \multicolumn{1}{>{\centering}m{3cm}}{{\cellcolor{gr}}Another
         Box with two\\
 Rows} &{\cellcolor{gr}}Student's\\
 Proficiency Level\tabularnewline
\hhline{----} 
\multicolumn{1}{|>{\centering}p{2.1cm}|}{Science} & 28 & 26 or above &     Proficient\tabularnewline
\hline 
\end{tabular*}


The colortbl.pdf file has lots of suggestions, none I 
understand very well. On p. 5 suggests it suggests: 
Replace "|" with vline or vrule, like this:

\begin{verbatim}
!{\color{gr}\vrule width 5pt}
\end{verbatim}

or maybe 
\begin{verbatim}
!{\color{gr}\vline}
\end{verbatim}

However, that causes the whole table to break because 
bottom right corner lines don't connect anymore. Look here:

\setlength\tabcolsep{0pt}
\begin{tabular*}{11cm}{@{\extracolsep{\fill}}>{\centering}p{2.1cm}|
>{\centering}m{2.9cm}|
>{\centering}m{3cm}|
>{\centering}m{2.9cm}|}
\multicolumn{4}{c}{\textbf{A Frustrating Table with 
white lines}}\tabularnewline
\hhline{~---}
 & \multicolumn{1}{>{\centering}m{2.9cm}%
!{\color{gr}\vrule width 1pt}%% where a vert bar would have been
}{{\cellcolor{gr}}Here's a box\\
 Score}& 
\multicolumn{1}{>{\centering}m{3cm}!{\color{gr}\vrule width 5pt}}
{{\cellcolor{gr}}Another
         Box with two\\
 Rows} &{\cellcolor{gr}}Student's\\
 Proficiency Level\tabularnewline
\hhline{----} 
\multicolumn{1}{|>{\centering}p{2.1cm}|}{Science} & 28 & 26 
or above & Proficient\tabularnewline
\hline 
\end{tabular*}


I believe this problem relates to the use of the array package and
some assumptions it makes about the sum of columns inside a table. This
fine answer on SE explains it.

\url{https://tex.stackexchange.com/questions/116917/why-is-my-tabular-wider-than-the-sum-of-its-columns-widths}

The total width of a table is the sum of the columns, plus the 
2 x tabcolsep, plus arrayrulewidth. But the tabular* is 
specified with the total width, and that's confusing 
So now, instead of specifying a
column width in cm, we have to do some ridiculous dance. 
Replace a column width like "2.1cm" with

\begin{verbatim}
{\dimexpr 2.1cm-2\tabcolsep-1.5\arrayrulewidth}
\end{verbatim}

Same calculation has to be applied to multicols as well.

\setlength\tabcolsep{0pt}
\begin{tabular*}{11cm}{@{\extracolsep{\fill}}
>{\centering}p{\dimexpr 2.1cm-2\tabcolsep-1.5\arrayrulewidth}|
>{\centering}m{\dimexpr 2.9cm-2\tabcolsep-1.5\arrayrulewidth}|
>{\centering}m{\dimexpr 3cm-2\tabcolsep-1.5\arrayrulewidth}|
>{\centering}m{\dimexpr 2.8cm-2\tabcolsep-1.5\arrayrulewidth}|}
\multicolumn{4}{c}{\textbf{A Frustrating Table with
 white lines}}\tabularnewline
\hhline{~---}
 & \multicolumn{1}{
>{\centering}m{\dimexpr 2.9cm-2\tabcolsep-1.5\arrayrulewidth}%
!{\color{gr}\vrule width 1pt}%% where a vert bar would have been
}{{\cellcolor{gr}}Here's a box\\
 Score}& 
\multicolumn{1}{>{\centering}m
{\dimexpr 3cm-2\tabcolsep-1.5\arrayrulewidth}
!{\color{gr}\vrule width 5pt}}
{{\cellcolor{gr}}Another
     Box with two\\
 Rows} &{\cellcolor{gr}}Student's\\
 Proficiency Level\tabularnewline
\hhline{----} 
\multicolumn{1}{|>{\centering}p{2.1cm}|}{Science} 
& 28 
& 26 or above 
& Proficient\tabularnewline
\hline 
\end{tabular*}

\end{document}
1
  • 6
    "In my code, I leave all of the packages we use because a smaller MWE won't necessarily reproduce the same problem the same way. " really you could remove almost all the packages and all the text except the table. It is easy for you to check that the example still produces the effect. using tabular* makes that tricky as you are adding gaps of unspecified width between the columns. It's easier with tabular to avoid these gaps. Mar 26, 2016 at 16:35

3 Answers 3

2

With tabularx instead of tabular*, and setting the overhang argument of columncolor to a suitable value, the thin white vertical lines disappear:

\documentclass[letterpaper,landscape,11pt,english]{article}
\usepackage[scaled=0.9]{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[landscape]{geometry}
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
\usepackage{array}
\usepackage{hhline}
\usepackage{color}
\usepackage{colortbl}
 \definecolor{gr}{RGB}{240,240,240}
\usepackage{tabularx}
\usepackage{babel}

\begin{document}

\renewcommand\arraystretch{1.25}
\begin{tabularx}{11cm}{
    |>{\centering}X|
    >{\centering}m{2.4cm}|
    >{\centering}m{2.4cm}|
    >{\centering}m{2.8cm}|}
    \multicolumn{4}{c}{\textbf{A Frustrating Table with
    white lines}}\tabularnewline[1ex]
    \hhline{~|---}
    \multicolumn{1}{c|}{} & \multicolumn{1}{>{\centering\columncolor{gr}}m{2.4cm}}%
    {Here's a box\\ Score}
                          & \multicolumn{1}{>{\centering\columncolor{gr}[\dimexpr\tabcolsep + 1pt\relax]}m{2.4cm}}%
    {Another Box\\ with two Rows} %
                          & \multicolumn{1}{>{\centering\columncolor{gr}[\tabcolsep]}m{2.8cm}|}%
    {Student's\\ Proficiency Level}
    \tabularnewline%
    \hline
    Science
                          & 28
                          & 26 or above
                          & Proficient\tabularnewline
    \hline
  \end{tabularx}

\end{document} 

enter image description here

2
  • Thanks for the help. I don't have any experience with tabularx, it appears to me not really necessary to fix problem. Instead, I'm delighted by the hint you have to replace \colorcell, which I had used inside the content of the cell, and insertion of \columncolor in the definition of the multicol. And, in particular, I'm delighted that you show the adjustment of the overlap should apply to the middle cell in the table! I was trying that, but changing all cells and getting gray overlap outside the table boundaries. You are smarter on that one!
    – pauljohn32
    Mar 28, 2016 at 19:46
  • 1
    As far as I remember from my trials, I had problems with a plain tabular, and it happened to work with tabularx – I am no X maniac ;o)
    – Bernard
    Mar 28, 2016 at 19:58
1

The thin white lines occur in some PDF engines (e.g. muPDF which is used in SumatraPDF for instance) when two adjacent cells are colored with two distinct instructions fill (the operator fill of PostScript which is called f in the PDF streams).

With colortbl, each cell is colored with its own instruction fill even when \columncolor or \rowcolor is used.

With nicematrix, an instruction \rowcolor or the use of the key fill of the command \Block will result in only one instruction fill in the PDF.

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

\begin{document}

\begin{NiceTabular}[hvlines,corners = NW,first-row]{cp[c]{3cm}p[c]{3cm}p[c]{3cm}}
\Block{1-4}{\textbf{A not so frustrating table}} \\
&  \Block[fill=gray!15]{1-3}{}
Here's a box Score & Another Box with two rows & Student's Proficiency Level \\
Science & 28 & 26 or above & Proficient 
\end{NiceTabular}
    
\end{document}

Moreover, in {NiceTabular}, you have a key hvlines to draw all the rules except in the empty corners, in the so-called ``first-row'' and in the blocks. The blocks are created by the command \Block.

Output of the above code

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

0

The white lines, which sometimes appear when dealing with custom lines, can also be corrected using tabularray

enter image description here

\documentclass{article}
\usepackage[landscape]{geometry}
    \geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
\usepackage{lmodern}
\usepackage[scaled=0.9]{helvet}
    \renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
    \definecolor{gr}{RGB}{240,240,240}
\usepackage{tabularray}
    \UseTblrLibrary{booktabs}


\begin{document}
\noindent%
\begin{tblr}{
        width = 11cm,
        colspec = {Q[2.1cm,l,m] X[c,m] X[c,m] X[c,m]},
        cell{2}{2-Z} = {bg=gr},
        hline{2} = {2-Z}{}, hline{3-Z},
        vline{1,3,4} = {3-Z}{},
        vline{3,4} = {2-2}{gr},
        vline{2,Z} = {2-Z}{},
    }
    \SetCell[c=4]{font=\bfseries,halign=center}
    A Frustrating Table with white lines \\
    & {Here's a box\\Score}
        & {Another Box with two\\Rows}
        & {Student's\\Proficiency Level} \\
    Science & 28 & 26 or above & Proficient \\
\end{tblr}
\end{document}

You must log in to answer this question.

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