3

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?

3
  • As always on the site you are more likely to get help if you provide something that others can test
    – daleif
    Jun 16, 2020 at 10:45
  • 2
    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
  • 3
    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

1 Answer 1

8

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}

Output of the above code

1
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.