9

I'm trying to add HTML code based color to my table, like so:

\usepackage[table]{xcolor}

\begin{tabular}{ |>{\columncolor[HTML]{F2FAF8}}c| p{11cm} |}
    \hline
CELL 1 & CELL 2\\ \hline
CELL 1 & CELL 2\\ \hline
CELL 1 & CELL 2\\ \hline
 \end{tabular}

however, the cells seem to overflow on top of the \hline, like so:

Bad table!

How do I prevent this from happening?

UPDATE in response to comments:

I tried:

\setlength{\arrayrulewidth}{1pt}
\begin{tabular}{ |>{\columncolor[HTML]{F2FAF8}}c| p{11cm} |}
    \hline
CELL 1 & CELL 2\\ \hline
CELL 1 & CELL 2\\ \hline
CELL 1 & CELL 2\\ \hline
 \end{tabular}

no go:

enter image description here

2 Answers2

6

I claim this is a problem with the dvi driver bleeding the coloured panels too far, but I see the same with dvipng You can compensate by over-printing an uncoloured table over the top so the rules are on top of the colour not adjacent.

Compare

enter image description here

and

enter image description here

\documentclass{standalone}

\usepackage[table]{xcolor}

\begin{document}


\def\foo#1{\begin{tabular}{ |>{#1}c| p{11cm} |}
    \hline
CELL 1 & CELL 2\\ \hline
CELL 1 & CELL 2\\ \hline
CELL 1 & CELL 2\\ \hline
 \end{tabular}}


\foo{\columncolor[HTML]{F2FAF8}}\llap{\foo{}}

\end{document}
David Carlisle
  • 757,742
0

The package nicematrix has tools which has been designed to address that kind of problem. With that package, the rules won't seem to disappear in some PDF viewers at some levels of zoom.

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

\begin{document}

\begin{NiceTabular}{>{\columncolor[HTML]{F2FAF8}}cp{11cm}}[color-inside,hvlines] CELL 1 & CELL 2\ CELL 1 & CELL 2\ CELL 1 & CELL 2\ \end{NiceTabular}

\end{document}

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

Output of the above code

F. Pantigny
  • 40,250