[Tex/LaTex] Broken tikz chains

tikz-chainstikz-pgf

I tried to use the tikz chains feature today, and all was good for a few hours, but now I get an error every time I try to use chains

./test.tex:7: Package pgfkeys Error: I do not know the key '/tikz/nonterminal' and I am going to ignore it. Perhaps you misspelled it. [    \node [nonterminal]]
./test.tex:8: Package pgfkeys Error: I do not know the key '/tikz/terminal' and I am going to ignore it. Perhaps you misspelled it. [    \node [terminal]]
./test.tex:9: Package pgfkeys Error: I do not know the key '/tikz/terminal' and I am going to ignore it. Perhaps you misspelled it. [    \node [terminal]]
./test.tex:10: Package pgfkeys Error: I do not know the key '/tikz/terminal' and I am going to ignore it. Perhaps you misspelled it. [    \node [terminal]]

And here is the code

\documentclass[a4paper]{memoir}
% Add packages
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{figure}
  \begin{tikzpicture}[start chain,node distance=5mm, every node/.style={on chain,join}, every join/.style={->}]
    \node [nonterminal]  {unsigned integer};
    \node [terminal]     {.};
    \node [terminal]     {digit};
    \node [terminal]     {E};
  \end{tikzpicture}
\end{figure}
\end{document}

Any good ideas on how to repair the chain?

Best Answer

As Qrrbrbirlbel (name chosen to be difficult to write? :p) said, you haven't defined your terminal and nonterminal style. The pgfkeys errors are hinting about this as they complain that tikz/nonterminaland tikz/terminalare unknown. Some times, TikZ recognise if you try to use keys from a tikzlibrary you should have loaded with usetikzlibrary, and will say so.

In the TIKZandPGF-manual the styles are set with tikzset, but are given in the tikzpicture options ([]) in the examples on page 60 and 61. You'll also need to load the shapes.misc library to be able to produce the rounded rectangle. The code is given below:

\documentclass[a4paper]{memoir}
\usepackage{tikz}
\usetikzlibrary{chains, shapes.misc}
\tikzset{
    nonterminal/.style={
      rectangle,
      minimum size=6mm,
      very thick,
      draw=red!50!black!50,
      top color=white,
      bottom color=red!50!black!20,
      font=\itshape},
    terminal/.style={
      rounded rectangle,
      minimum size=6mm,
      very thick,draw=black!50,
      top color=white,bottom color=black!20,
      font=\ttfamily}
    }
\begin{document}
\begin{figure}
  \begin{tikzpicture}[start chain,node distance=5mm, every node/.style={on chain,join}, every join/.style={->}]
    \node [nonterminal]  {unsigned integer};
    \node [terminal]     {.};
    \node [terminal]     {digit};
    \node [terminal]     {E};
  \end{tikzpicture}
\end{figure}
\end{document}

which produces the output

enter image description here

Related Question