2

I am having trouble with including a tikz flow chart in my code.

In my preamble I have included

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{shapes,arrows}

and this is the flow chart:

\begin{figure}[hc]      
\begin{tikzpicture}[node distance = 4cm, auto]
% Place nodes
\node [block] (Bio) {Biological Processes};
\node [block, below of=Bio] (Nut) {Nutrient Levels};
    \node [block, left of=Nut] (Growth) {Growth/Mortality Rates};
    \node [block, right of=Nut] (Predprey) {Predator-Prey Interactions};

    \path [line] (Bio) -- node[name=uptake] {} (Nut);
    \path [line] (Bio) -- node[name=grazing] {} (Growth);
    \path [line] (Bio) -- node[name=pgrowth] {} (Predprey);

\end{tikzpicture}
\caption{\textbf{The biological processes governing the dynamics of plankton populations}}      
\label{bioprocesses}    
\end{figure}

I have another similar flow chart further down in my code, which is of a similar format

\begin{figure}[hc]      
\begin{tikzpicture}[node distance = 3cm, auto]

\node [block] (Nitr) {Nitrates};
\node [block, below of=Nitr] (Phyto) {Phytoplankton};

    \path [line] (Nitr) -- node[name=uptake] {nutrient uptake} (Phyto);

\node [block, below of=Phyto] (Zoo) {Zooplankton};

    \path [line] (Phyto) -- node[name=grazing] {grazing} (Zoo);

    \node [output, right of=Phyto] (Pgrowth) {};
    \node [output, right of=Zoo] (Zgrowth) {};
    \node [output, below of=Zoo] (Zdeath) {};

    \path [line] (Phyto) -- node[name=pgrowth] {growth} (Pgrowth);
    \path [line] (Zoo) -- node[name=zgrowth] {growth} (Zgrowth);
    \path [line] (Zoo) -- node[name=zdeath] {death} (Zdeath);

    \path[line] (Phyto) -- ([xshift=-1.75cm,yshift=0cm]Phyto.west) |- node[name=nutre] {nutrient recycling} (Nitr);


\end{tikzpicture}
\caption{\textbf{Population Interactions}}      
\label{flowchart}   
 \end{figure}

The thing that I do not understand is WHY flow chart 1 can only be placed in the same chapter as flow chart 2 (it compiles perfectly here). Every time I try to place it elsewhere, it comes up with:

package pgfkeys error i don't know the key '/tikz/line'

package pgfkeys error i don't know the key '/tikz/block'

Surely if it compiles in one chapter then I should be able to copy and paste it into another and it should still work?

EDIT: Minimal Example

\documentclass[10pt,a4paper]{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{shapes,arrows}


\begin{document}

\section{FIRST SECTION}

Here is my first section.

\begin{figure}[hc]      
\begin{tikzpicture}[node distance = 4cm, auto]
\node [block] (main) {MAIN};
\node [block, below of=main] (Opt1) {Option 1};
\node [block, left of=Opt1] (Opt2) {Option 2};
\node [block, right of=Opt1] (Opt3) {Option 3};

\path [line] (main) -- node[name=line1] {} (Opt1);
\path [line] (main) -- node[name=line2] {} (Opt2);
\path [line] (main) -- node[name=line3] {} (Opt3);

\end{tikzpicture}
\caption{\textbf{First diagram}}      
\label{diagram1}    
\end{figure}

\section{SECOND SECTION}

Here is my second section.

\begin{figure}[hc]      
\begin{tikzpicture}[node distance = 3cm, auto]

\node [block] (Top) {Top Box};
\node [block, below of=Top] (Middle) {Middle Box};
\node [block, below of=Middle] (Bottom) {Bottom Box};
\node [output, below of=Bottom] (output) {};

\path [line] (Top) -- node[name=down1] {line down} (Middle);
\path [line] (Middle) -- node[name=down2] {line down} (Bottom);
\path [line] (Bottom) -- node[name=down3] {line down} (output);

\end{tikzpicture}
\caption{\textbf{Second diagram}}      
\end{figure}

\end{document}
KEJ
  • 21
  • You apparently have a local assignment for the styles line and block. Is the \tikzset defining these in a LaTeX group (starting with \begin and ending with \end)? I advice you to move this assignment (the \tikzset command) to the preamble. We could help you more if we see a minimal working example (MWE). – Qrrbrbirlbel May 05 '13 at 12:35
  • Welcome to TeX.sx! People would be able to help you more quickly if you edited your code into a minimal working example (MWE), starting with \documentclass{...} and ending with \end{document}. – jub0bs May 05 '13 at 12:35
  • Thank you, sorry I didn't want to alter the code too much and accidentally remove whatever was causing the error. I'll try a MWE and see if that still has the same problem. – KEJ May 05 '13 at 12:37
  • 1
    But reducing the code to isolate the cause of the error is part of debugging :) – jub0bs May 05 '13 at 12:41
  • I have tried a MWE, but it now won't compile either diagram though for the same reason. It also says: "Package \pgf plots Warning: running in backwards compatibility mode (unsuitable tick labels, missing features)." (eek!) – KEJ May 05 '13 at 13:08
  • @KEJ Well, of course. Where are the styles line and block defined? (The pgfplots error also says Consider writing \pgfplotsset{compat=1.8} into your preamble..) – Qrrbrbirlbel May 05 '13 at 13:10
  • Thank you very much, the example I was following didn't include the definitions so I didn't realise they weren't inbuilt with the package. After your hint I have found how to define them.

    I have added in the following to the preamble and it seems to work.

    \tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em] \tikzstyle{line} = [draw, text centered , -latex'] \tikzstyle{output} = [fill=white]

    Thanks again, very kind of everyone.

    – KEJ May 05 '13 at 13:24
  • You’re welcome. You may better use \tikzset as per Should \tikzset or \tikzstyle be used to define TikZ styles? – Qrrbrbirlbel May 05 '13 at 14:05
  • @Qrrbrbirlbel Isn't there something fishy going on, though? AFAIK, line and block are defined in the shapes TikZ library, which is loaded here... – jub0bs May 05 '13 at 14:09
  • @Qrrbrbirlbel Sorry, my mistake. Forget what I wrote :) I'll delete that shortly. – jub0bs May 05 '13 at 14:19

0 Answers0