I am looking for a convenient way to set the background of tabular cells. I'd like to do two things:
(1) Set the background shaded in a color
(2) Set the background hatched
I learned that the TikZ package provides means to do this but I am unable to come up with a solution that does not use matrices (such as here: http://www.texample.net/tikz/examples/timetable/) but instead uses the tabular package.
Here's what I'd like to do:
\documentclass{article}
\begin{document}
\begin{tabular}{|l|l|l|}
\hline
1 & \setBGGray 2 & 3 \\\hline
4 & 5 & 6 \\\hline
7 & \setBGHatched 8 & 9 \\\hline
\end{tabular}
\end{document}
The output should look like this:
Can someone please help me achieving this using tabular
(or tabularx
) and TikZ?
Best Answer
My answer to Gradient color in one cell of a table produces shaded cells and can easily be adapted to produce hatched patterns. This solution works with
tabular
,tabularx
(tabulary
will also be OK I imagine, although I didn't test it) and with\multicolumn
:And the numeric matrix zoomed in:
If you need to repeatedly use the same hatching in multiple cells, the above approach is a little clumsy. But you can define a counter and a single command that does all the neccessary stuff (I removed the vertical lines as there were some glitches I could not fix easily, but you should not use vertical lines in tables anyway ;-):