[Tex/LaTex] trouble getting Tikz matrix to compile

nodestikz-matrixtikz-pgf

In advance of a summer class I'm teaching, I decided to try compiling my notes, which I haven't touched in any way, shape or fashion for 4-5 months. However, in that interval, I've updated laTeX packages as new updates have come online (using MikTeX 2.9). I have a large number of lectures containing tikzpictures, of the following general form (all of which used to compile perfectly):

  \documentclass{article}

   \usepackage{tikz}
      \usetikzlibrary{snakes,shapes,arrows,matrix,positioning}

      \begin{document}

  \begin{figure}[h]
  \centering
  \rule[-1.25cm]{0pt}{3.25cm}
    \begin{tikzpicture}[>=stealth,->,shorten >=1.5pt,line width=0.75pt]
   \matrix (a) [matrix of nodes,row sep=0.5em, column sep=3em]
   { \node[circle,draw,font=\small,minimum width=1cm] {\sffamily{1}};  &   \node[circle,draw,font=\small,minimum width=1cm]{\sffamily{2}}; &  \node[circle,draw,font=\small,minimum width=1cm]    {\sffamily{3}}; \\};
 \path[>=stealth,font=\small] (a-1-1) edge node[below] {$S_o$} (a-1-2);
 \path[>=stealth,font=\small] (a-1-2) edge node[below] {$S_1$} (a-1-3);
 \path[>=stealth,->,font=\small] (a-1-2) edge [bend right=50] node [above,near start] {$S_1F_2$} (a-1-1) ;
 \path[>=stealth,->,font=\small] (a-1-3) edge [bend right=55] node [above,near start] {$S_2F_3$} (a-1-1) ;
    \end{tikzpicture}
  \end{figure}

\end{document}

When I try to compile the preceding MWE, I get all sorts of error messages about 'no shape named a-1-1 is know…' etc. etc.

Which I find odd, because clearly, when it compiled perfectly before, said shape was known. I gather something has changed.

Any insights/pointers to the obvious most appreciated.

Best Answer

Things have changed with tikz v3.

  \documentclass{article}

   \usepackage{tikz}
      \usetikzlibrary{snakes,shapes,arrows,matrix,positioning}
   \tikzset{mynode/.style={circle,draw,font=\small,minimum width=1cm,font=\sffamily}
   }
      \begin{document}

  \begin{figure}[h]
  \centering
  \rule[-1.25cm]{0pt}{3.25cm}
    \begin{tikzpicture}[>=stealth,->,shorten >=1.5pt,line width=0.75pt]
   \matrix (a) [matrix of nodes,row sep=0.5em, column sep=3em]
    {|[mynode]|1  &   |[mynode]|2 &  |[mynode]|3 \\};
 \path[>=stealth,font=\small] (a-1-1) edge node[below] {$S_o$} (a-1-2);
 \path[>=stealth,font=\small] (a-1-2) edge node[below] {$S_1$} (a-1-3);
 \path[>=stealth,->,font=\small] (a-1-2) edge [bend right=50] node [above,near start] {$S_1F_2$} (a-1-1) ;
 \path[>=stealth,->,font=\small] (a-1-3) edge [bend right=55] node [above,near start] {$S_2F_3$} (a-1-1) ;
    \end{tikzpicture}
  \end{figure}

\end{document}

enter image description here

BTW \sffamily{1} is wrong as \sffamily is a switch. Use font=\sffamily as the option to the node instead..

Edit:

You can customize each node by putting the attributes in a \tikzset. This way you have more control over the individual nodes.

  \documentclass{article}

   \usepackage{tikz}
      \usetikzlibrary{snakes,shapes,arrows,matrix,positioning}
   \tikzset{mynode/.style={circle,draw,font=\small,minimum width=1cm,font=\sffamily},
            every node/.style={minimum width=1cm},
            firstnode/.style={ellipse,draw,font=\small\sffamily,fill=red!10}, 
            secondnode/.style={ellipse,draw,font=\small\sffamily,fill=green!10},
            thirdnode/.style={ellipse,draw,font=\small\sffamily,fill=brown!10},
            fourthnode/.style={ellipse,draw,font=\small\sffamily,fill=black!10}
   }
      \begin{document}

  \begin{figure}[h]
  \centering
  \rule[-1.25cm]{0pt}{3.25cm}
    \begin{tikzpicture}[>=stealth,->,shorten >=1.5pt,line width=0.75pt]
   \matrix (a) [matrix of nodes,row sep=0.5em, column sep=3em]
    {|[firstnode]|1  &   |[secondnode]|2 &  |[thirdnode]|3 \\};
 \path[>=stealth,font=\small] (a-1-1) edge node[below] {$S_o$} (a-1-2);
 \path[>=stealth,font=\small] (a-1-2) edge node[below] {$S_1$} (a-1-3);
 \path[>=stealth,->,font=\small] (a-1-2) edge [bend right=50] node [above,near start] {$S_1F_2$} (a-1-1) ;
 \path[>=stealth,->,font=\small] (a-1-3) edge [bend right=55] node [above,near start] {$S_2F_3$} (a-1-1) ;
    \end{tikzpicture}
  \end{figure}

\end{document}

enter image description here

This way the styles will be usable across tikzpictures.