[Tex/LaTex] How to color table columns


I've found question How do I fill table cells with a background color?, but the link to the documentation isn't helping me at all.

I'd like to know how to color a table column given my column code, but the documentation only gives the syntax of the command. It doesn't give any code example of where to use it.



As you can see, I got \cellcolor to work, but I don't want to color individual cells. I want to color a whole column of the table. Does anybody know how I can go about to do this?

Best Answer

Here a small example, which might be of help to you.

  • Define your own color using \definecolor{Gray}{gray}{0.85}
  • Define your own columns using \newcolumntype{a}{>{\columncolor{Gray}}c}
  • You are ready to go.






\begin{tabular}{l | a | b | a | b}
\mc{1}{}  & \mc{1}{x} & \mc{1}{y} & \mc{1}{w} & \mc{1}{z} \\
variable 1 & a & b & c & d \\
variable 2 & a & b & c & d \\ \hline




Related Question