Ad Code

Responsive Advertisement

Coloring Rows and Columns in Table in LaTeX

 PACKAGES TO BE USED

\usepackage {color, colortbl}


DEFINING COLOR

Format: \definecolor{colorname}{colorsystem}{definition}

\definecolor{Red}{rgb}{1.0,0.5,0.5}

\definecolor{Gray}{gray}{0.7}

👉 notice how rgb and gray colors defined


DEFINING COLUMN COLOR

\newcolumntype{g}{>{\columncolor{Red}}c}


COLORING A ROW

Format: \rowcolor{colorname} 

👉just above row to be colored

COLORING A CELL

Format: \cellcolor{colorname}{columnvalue}

TABLE WITH COLORED ROWS AND COLUMNS

\begin {tabular}

{|c|c|c|c|c|g|g|} 👈 notice how column color is applied to last 2 columns

\hline

\rowcolor{Gray}👈 notice how row color is applied to row just below

M & T & W & T & F & S & S \\ \hline

& & & & & 1 & 2 \\ \hline

3 & \cellcolor{Red}{4} & 5 & 6 & \cellcolor{Red}{7} & 8 & 9 \\ \hline

10 & 11 & 12 & 13 & \cellcolor{Red}{14} & 15 & 16 \\ \hline 👈 notice how color is applied to a cell

17 & 18 & 19 & 20 & \cellcolor{Blue}{21} & 22 & 23 \\ \hline

24 & 25 & 26 & 27 & 28 & 29 & 30 \\ \hline

\end {tabular}


OUTPUT




Post a Comment

0 Comments