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?
1 Answer
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 writec|c|c
instead ofC|C|C
in the preamble of{NiceTabular}
(but there is an option for backward compatibility). Jul 18, 2020 at 20:45
\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.