# Column shading, alternative to xcolor package

I want every second column in my table to have a shading for improved readability. I have used the xcolor package \usepackage[table]{xcolor} using the command \cellcolor[gray]{0.9}. It works, but it messes with the grid lines and looks absolutely unprofessional. Is there a better way?

• As always on the site you are more likely to get help if you provide something that others can test Jun 16, 2020 at 10:45
• you can look at tikz tables, or I usually recommend not having rules and coloured backgrounds at the same time, do you really need both? Jun 16, 2020 at 10:56
• if it's the whole column why not \columncolor rather than \cellcolor ? neither in fact should affect the rules in any way although you may see some artefacts at some zoom levels in some viewers. Jun 16, 2020 at 10:59

With {NicaTabular} of nicematrix (≥ 4.0 2020-05-08), we have tools to color cells, rows and columns before the rules are drawn. The rules won't vanish in the PDF viewers at some levels of zoom.

\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}
\begin{document}

\begin{NiceTabular}{C|C|C}%
[code-before = \columncolor{red!15}{2}]
rosa          & lilium     & tulipa    \\
phaloaenopsis & dianthus   & freesia   \\
alstroemeria  & gladiolus  & narcissus \\
papaver       & helianthus & allium    \\
alyssum       & angelonia  & hibiscus  \\
hydrangea     & saporania  & sedum     \\
\end{NiceTabular}

\end{document}


• In this answer, since version 5.0 of nicematrix one must write c|c|c instead of C|C|C in the preamble of {NiceTabular} (but there is an option for backward compatibility). Jul 18, 2020 at 20:45