1

I'd like to colorize the empty cell in row #2 and also the merged rows. How can I do this?

\documentclass{article}
\begin{document}

\begin{center}
\begin{tabular}{ |c| c| c |c |c |c|}
\hline
chapter & \multicolumn{5}{|c|}{rules in sub-chapters}  \\
\hline
& first & second & third& fourth & total  \\
\hline
 first & 75 & 73 & 93 & 110 & 351 \\
 \hline
  second & 72 & 38 & 73 & 85 & 268 \\
 \hline
 total & \multicolumn{4}{|c|}{} & 3981 \\
 \hline
 \end{tabular}
\end{center}

\end{document}

Table

linuxfan
  • 437
  • Which color(s) do you have in mind? – Mico Feb 11 '17 at 18:14
  • Any color is fine. Also, is it possible to fill it with lines (e.g lines inclined at 45 degrees) – linuxfan Feb 11 '17 at 18:17
  • @linuxfan If you want lines inside a cell have a look at diagbox. – TeXnician Feb 11 '17 at 18:19
  • 2
    @TeXnician - I suspect that what the OP has in mind is not inserting a single, diagonal line. Instead, it may be a method for hatching and cross-hatching the cell contents. Let's see if the OP clarifies his/her question. – Mico Feb 11 '17 at 18:28
  • @Mico guessed right. I want to draw a bunch of lines in the empty cells, just like we do on paper to indicate that there's nothing in that cell. Perhaps hatching is the right term for it? – linuxfan Feb 11 '17 at 18:31
  • 2
    Please look at http://tex.stackexchange.com/a/236061/124577 for hatchin of cells. Maybe http://tex.stackexchange.com/a/67096/124577 too. – TeXnician Feb 11 '17 at 18:31
  • 2
    Amazing - you guys are the best :) – linuxfan Feb 11 '17 at 18:32

1 Answers1

2

You might want to use xcolor with the table option and its \cellcolor.

colored table

\documentclass{article}
\usepackage[table]{xcolor}

\begin{document}

\begin{center}
\begin{tabular}{ |c| c| c |c |c |c|}
\hline
chapter & \multicolumn{5}{c|}{rules in sub-chapters}  \\
\hline
\cellcolor{green}& first & second & third& fourth & total  \\
\hline
 first & 75 & 73 & 93 & 110 & 351 \\
 \hline
  second & 72 & 38 & 73 & 85 & 268 \\
 \hline
 total & \multicolumn{4}{c|}{\cellcolor{green}} & 3981 \\
 \hline
 \end{tabular}
\end{center}

\end{document}

Update: As Mico suggested you should change your \multicolumn column definition to c| instead of |c| (for reasons of column calculation).

TeXnician
  • 33,589