18

I'm trying to highlight a whole row/column of a TikZ \matrix[matrix of nodes].

Luckily, for TikZ matrix we have row/column selectors. So, in theory, the above should be achieved by the following code:

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{matrix}

\begin{document}

  \begin{tikzpicture}

    \matrix[matrix of nodes,nodes={draw},row 2/.style={fill=blue!20}] {
      a11 & a12 & a13 \\
      a21 & a22 & a23 \\
      a31 & a32 & a33 \\
    };

  \end{tikzpicture}

\end{document}

...but that simply doesn't work. Am I missing something? To produce the image above, I had to manually insert a |[fill=blue!20]| before every element of the 2nd row. Defining a style like \tikzstyle{foo}=[fill=blue!20] and setting row 2/.style={foo} doesn't work either. In the same time, using row/column selectors to set foreground color works (simply [blue!20] instead of [fill=blue!20]), as well as setting many other properties like font face & size. Seems like a bug in TikZ? Tested with pdfLaTeX, XeLaTeX and luaLaTex on TeXLive 2011.

Ochkarik
  • 393

1 Answers1

16

You need to pass the option to the nodes

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

  \begin{tikzpicture}

    \matrix[matrix of nodes,nodes={draw},row 2/.style={nodes={fill=blue!20}}] {
      a11 & a12 & a13 \\
      a21 & a22 & a23 \\
      a31 & a32 & a33 \\
    };

  \end{tikzpicture}

\end{document}

enter image description here

percusse
  • 157,807
  • thanks a lot! And, if we do not use nodes=..., then what does the style apply to? Wonder why setting foreground color still works. – Ochkarik Nov 02 '12 at 19:26
  • 1
    @Ochkarik The style applies to the cell itself but cell doesn't have any fill directive (only the color). Had it been the case then it would have been picked up by it. Probably you have provided a general red kind of option and it's been picked by the text itself too. – percusse Nov 02 '12 at 20:29
  • 1
    @Ochkarik The discussion in the comments of http://tex.stackexchange.com/a/18353/9428 seems to be related – sappjw Dec 18 '12 at 15:35