TransWikia.com

How do I prevent cellcolor from over effect of hline

TeX - LaTeX Asked by blueberryfields on June 2, 2021

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 Answers

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}


deffoo#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}

Correct answer by David Carlisle on June 2, 2021

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}}[colortbl-like,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

Answered by F. Pantigny on June 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP