Starting from the answer to this question, I have modified the code in order to have 4 different kind of cells (instead of two). Here the code:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\tikz[%
every cell 0/.style={draw=black
, opacity=.5
, minimum height=0.1em
, outer sep=0pt},
every cell 1/.style={draw=black
, fill=gray
, opacity=.5
, minimum height=0.1em
%, width=0.1em,
%, depth=0.1em
, outer sep=0pt},
every cell 2/.style={draw=red
, fill=gray
, minimum height=0.1em
%, width=0.1em,
%, depth=0.1em
, outer sep=0pt},
every cell 3/.style={draw=black
, fill=gray
, minimum height=0.1em
%, width=0.1em,
%, depth=0.1em
, outer sep=0pt}
]
\foreach \row [count=\y] in {%
{0,0,0,0,0,1,1,1,0,0,0},%
{0,0,0,1,1,1,0,1,1,0,0},%
{0,0,0,1,0,0,0,0,1,0,0},%
{0,0,0,2,0,0,0,1,1,0,0},%
{0,0,0,3,0,0,0,1,0,0,0},%
{0,0,1,1,0,0,0,1,0,0,0},%
{0,0,1,1,0,0,0,1,1,1,1},%
{0,0,1,1,0,0,0,0,0,0,0},%
{1,1,1,1,0,0,0,0,0,0,0}}%
\foreach \cell [count=\x] in \row
\path [every cell, every cell \cell]
(\x,-\y) rectangle ++(1,1);
\end{document}
And this is the output (with two external edges missed):
I would like to put the cells corresponding to 2 in the foreground. Indeed the red border is visible only where the opacity parameter is setted (i.e. cells of type 0,2 not 3). In particular I would like to see the red rectangle without setting the opacity for the other cells. Here a similar question.


\foreachloop should be contained in a pair of{}. – Herr K. Oct 15 '15 at 13:582cell, or do want to fill it with red? – Tom Bombadil Oct 15 '15 at 14:02