latex: color one column

Viewed 81

I would like to create a table like the following: enter image description here

in which only one column has a color and the color is applied to alternate rows.

The basic table would be:

\documentclass{article}

\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx} 
\usepackage{multirow}
\usepackage{float}
\usepackage[margin=2cm,left=2.5cm,includefoot]{geometry}

\begin{document}

\begin{table}[!h]
\centering
\caption{HS Sections}
    \begin{tabular}{ccc}
              & node & degree \\
    \hline
     & 1 & 1 \\
     & 2 & 2 \\
     & 3 & 2 \\
     & 4 & 4 \\
     & 5 & 2 \\
     & 6 & 2 \\
     & 7 & 1 \\
    \hline
    \end{tabular}
\label{tab:Table}
\end{table}

\end{document}
1 Answers

You could either manually use \cellcolor{...} to colour the cells you want or you could cheat a bit by colouring the whole rows in alternate colours and then overpaint the cells of the first column with white:

\documentclass{article}

\usepackage[table]{xcolor} 

\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx} 
\usepackage{multirow}
\usepackage{float}
\usepackage[margin=2cm,left=2.5cm,includefoot]{geometry}

\begin{document}

\begin{table}[!h]
\centering
\caption{HS Sections}
\rowcolors{2}{cyan!50}{white}
    \begin{tabular}{>{\cellcolor{white}}cc}
     node & degree \\
    \hline
     1 & 1 \\
     2 & 2 \\
     3 & 2 \\
     4 & 4 \\
     5 & 2 \\
     6 & 2 \\
     7 & 1 \\
    \hline
    \end{tabular}
\label{tab:Table}
\end{table}

\end{document}

enter image description here

Related