8

I've been doing some diagrams using TikZ with matrix as the layout.

While using Pgf version 2.10, everything went well, but now I'm using Pgf version 3.0.0 (TexLive2013) and there's a problem I'm almost sure is related to using custom styled nodes as elements of the table. The problem is that I cannot use the normal reference ((matrixName)-(rowNum)-(colNum)), because it's not available.

I've reduced my document to a MWE:

\documentclass[12pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, matrix}

\tikzset{newIdea/.style={rectangle, fill=blue!90},
         newPlan/.style={rectangle, rounded corners=2mm, text=white, fill=blue!90}
}

\begin{document}

    \begin{tikzpicture}
        \matrix (magic) [matrix of nodes, column sep=10mm]
        {       
            \node[newIdea] {8}; & \node[newPlan] {1}; & \node[newIdea] {6}; \\
        };        
        \draw[thick,red,->] (magic-1-1) |- (magic-1-2);
    \end{tikzpicture} 

\end{document}

Using Pgf 2.10, everything works; using Pgf 3.0.0 I get the following error message:

Package pgf Error: No shape named magic-1-1 is known.

percusse
  • 157,807

1 Answers1

10

Since version 3.0.0 when you use a matrix of nodes it seems that \node is not allowed inside cells (I initially didn't like this feature (I hope it's a feature and not a bug), but after thinking about it, it kind of makes perfect sense); however, you can still use the |[<options>]| syntax to modify the nodes:

\documentclass[12pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, matrix}

\tikzset{newIdea/.style={rectangle, fill=blue!90},
         newPlan/.style={rectangle, rounded corners=2mm, text=white, fill=blue!90}
}

\begin{document}

    \begin{tikzpicture}
        \matrix (magic) [matrix of nodes, column sep=10mm]
        {       
            |[newIdea]|8 &  |[newPlan]|1 & |[newIdea]|6 \\
        };        
        \draw[thick,red,->] (magic-1-1) |- (magic-1-2);
    \end{tikzpicture} 

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • Interesting, but (tell me if I'm wrong) here we have two syntaxes that are incompatible between each version... – Nicolás Ozimica Mar 22 '14 at 02:26
  • @Nicolás Indeed; it's a shame, since some 2.10 codes will not work, but, on the other hand (as I mentioned in my answer), the change makes sense to me (it should have been included earlier). Till Tantau is the only one who can say what motivated him to this. – Gonzalo Medina Mar 22 '14 at 02:30
  • @Nicolás: I answered just yesterday a similar question on the italian forum. I also don't like this behaviour; another way to get rid of the problem is to specifically give the correct names (i.e. magic-1-1 to the nodes). However, this is a valid workaround if you have few \nodes within the matrix. For your case, Gonzalo's solution is perfect. – Claudio Fiandrino Mar 22 '14 at 08:11
  • Extending Nicolás' comment: This would be a patch for your MWE. \node[newIdea](magic-1-1){8}; & \node[newPlan](magic-1-2){1}; – Malipivo Mar 22 '14 at 09:07
  • @ClaudioFiandrino: In some cases I use matrix just to avoid having to give a specific name to each node... – Nicolás Ozimica Mar 23 '14 at 15:21
  • 1
    @Nicolás: I know, that's exactly the potentiality of matrix; however, if you wish to keep your syntax you have to give name to the nodes, otherwise you have to use Gonzalo's way. – Claudio Fiandrino Mar 23 '14 at 15:56
  • Is it not possible to use compat for these scenarios? – Sean Allred Aug 11 '15 at 13:06
  • @SeanAllred I am not sure what you mean. pgfplots has acompat option but I'm not aware TikZ offers this feature too. Perhaps I am misunderstanding your comment? – Gonzalo Medina Aug 11 '15 at 15:25
  • @GonzaloMedina Oh, no you didn't misunderstand, I mis-remembered :( Thanks :) – Sean Allred Aug 11 '15 at 16:38