I made a table with the following code and the hhline
package:
\documentclass{article}
\usepackage{hhline}
\begin{document}
\begin{tabular}{l || l l l l l | l}
& 1 & 2 & 3 & 4 & 5 & 6\\\hhline{=#=====|=}
1 & 1 & 1 & 1 & 1 & 1 & 0\\
2 & 1 & 1 & 1 & 1 & 1 & 0\\
3 & 1 & 1 & 1 & 1 & 1 & 0\\
4 & 1 & 1 & 1 & 1 & 1 & 0\\
5 & 1 & 1 & 1 & 1 & 1 & 0\\\hline
6 & 0 & 0 & 0 & 0 & 0 & 1
\end{tabular}
\end{document}
Now, I would like to colour the 5×5 block in a specific colour, and the 1×1 block in another colour. The other cells should remain as they are.
I have seen Color merged and regular cells in a table individually which suggests \cellcolor
, \rowcolor
and columncolor
– however, in this case I could only use \cellcolor
, since there are no full rows or columns. But that would mean I have to type 26 times \cellcolor
. Is there no efficient way to do this (either algorithmically or by colouring a whole block at once)?
Best Answer
Manual Solution: You can apply
\rowcolor
and selectively color in white the cells which should not have color\ColorBlock{<start row>}{<end row>}{<color>}
Usingcollcell
package we can define a macro which specifies which rows of the table to color. This applies only to columns with theL
alignment defined in the MWE.Code:
Code:
\ColorBlock{<start row>}{<end row>}{<color>}