# TikZ flowchart for a poster

I'm making a poster and need to include a flowchart. I've never done this, so I'm starting with the example in the manual. Problem is, it doesn't work.

! Package pgfbasematrix Error: Single ampersand used with wrong catcode.


I googled but none of the solutions found so far fixed this. As I'm a total newb to TikZ, a matrix seems simpler to me, so I would really like to use it.

This is the ME (although I can't compile it, and the errors are different from my full-blown document):

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,matrix}
\begin{document}
\begin{tikzpicture}
[auto,
decision/.style={diamond, draw=blue, thick, fill=blue!20,text width=4.5em, text badly centered,inner sep=1pt},
block/.style={rectangle, draw=blue, thick, fill=blue!20,text width=5em, text centered, rounded corners,minimum height=4em},
line/.style={draw, thick, -latex’,shorten >=2pt},
cloud/.style={draw=red, thick, ellipse,fill=red!20,minimum height=2em}]

\matrix [column sep=5mm,row sep=7mm]
{
% row 1
\node [cloud] (expert){expert}; &
\node [block] (init){initialize model}; &
\node [cloud] (system){system}; \\
% row 2
& \node [block] (identify) {identify candidate model}; & \\
% row 3
\node [block] (update){update model}; &
\node [block] (evaluate) {evaluate candidate models}; & \\
% row 4
& \node [decision] (decide) {is best candidate}; & \\
% row 5
& \node [block] (stop){stop}; & \\
};
\begin{scope}[every path/.style=line]
\path   (init)-- (identify);
\path   (identify) -- (evaluate);
\path   (evaluate) -- (decide);
\path   (update)|- (identify);
\path   (decide)-| node [near start] {yes} (update);
\path   (decide)-- node [midway] {no} (stop);
\path [dashed] (expert)-- (init);
\path [dashed] (system)-- (init);
\path [dashed] (system)|- (evaluate);
\end{scope}
\end{tikzpicture}
\end{document}


My question is: what's wrong? This is my first contact with TikZ, so I'm totally lost.

-
Your errors are due to \begin{scope}[every path/.style=line]\end{scope}. I don't know enough to know why is that so. – ipavlic Apr 20 '11 at 12:20
Also, you might want to look at "Placing nodes using relative placement", Section 3.8 of the TikZ/PGF manual. It might be better than a matrix for what you want... – Seamus Apr 20 '11 at 12:25

You have an error in your definition of the line style:

line/.style={draw, thick, -latex’,shorten >=2pt}


That should be -latex', not -latex’.

In addition, you mentioned that you're making a poster: do you happen to be using the beamerposter package? If so, you can add the fragile option to the frame to get rid of the pgfbasematrix error:

\begin{frame}[fragile]
...

-
Good catch--I got it at the same time. – Matthew Leingang Apr 20 '11 at 12:29

You need to replace your ampersands with something else. See section 16.5 of the TikZ/PGF manual. I needed to make several changes to the MWE based on answers/comments from ipavlic and LianTze Lim, but given the original error quoted in the question, I maintain that the problem is with ampersands.

Having edited a typo in the definition of lines and added the scopes library, this compiles for me:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,matrix,scopes}
\begin{document}
\begin{tikzpicture}
[auto,
decision/.style={diamond, draw=blue, thick, fill=blue!20,text width=4.5em, text badly centered,inner sep=1pt},
block/.style={rectangle, draw=blue, thick, fill=blue!20,text width=5em, text centered, rounded corners,minimum height=4em},
line/.style={draw, thick, -latex', shorten >=2pt},
cloud/.style={draw=red, thick, ellipse,fill=red!20,minimum height=2em}]

\matrix [column sep=5mm,row sep=7mm,ampersand replacement=\&]
{
% row 1
\node [cloud] (expert){expert}; \&
\node [block] (init){initialize model}; \&
\node [cloud] (system){system}; \\
% row 2
\& \node [block] (identify) {identify candidate model}; \& \\
% row 3
\node [block] (update){update model}; \&
\node [block] (evaluate) {evaluate candidate models}; \& \\
% row 4
\& \node [decision] (decide) {is best candidate}; \& \\
% row 5
\& \node [block] (stop){stop}; \& \\
};
\begin{scope}[every path/.style=line]
\path   (init)-- (identify);
\path   (identify) -- (evaluate);
\path (evaluate) -- (decide);
\path   (update)|- (identify);
\path   (decide)-| node [near start] {yes} (update);
\path   (decide)-- node [midway] {no} (stop);
\path [dashed] (expert)-- (init);
\path [dashed] (system)-- (init);
\path [dashed] (system)|- (evaluate);
\end{scope}
\end{tikzpicture}
\end{document}

-
This doesn't work with your MWE. I don't know why. But that's what the problem is: you need to use an ampersand replacement. – Seamus Apr 20 '11 at 12:22
Without replacing ampersands, Santiago's MWE works by removing scope. So the issue might be related to the scope command -- apparently, scopes library was not included. – ipavlic Apr 20 '11 at 12:22
Hmm, it worked for me even without the scopes library. I thought the error was a typo in -latex'. – LianTze Lim Apr 20 '11 at 12:28
Right... but without the scope env it's useless. Since this is an example from the manual, shouldn't it work?? Thanks for the help so far – Santiago Apr 20 '11 at 12:30
@ipavlic @LianTze Lim The MWE appears to be faulty, but given the error message the OP quotes from their original problem, it looks more likely to be a problem with the ampersands... – Seamus Apr 20 '11 at 12:30