为什么我可以在一个章节中完美地编译 tikzpicture,但在另一个章节中却不能?

为什么我可以在一个章节中完美地编译 tikzpicture,但在另一个章节中却不能?

我在代码中包含 tikz 流程图时遇到了麻烦。

我在序言中提到

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

这是流程图:

\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}

我的代码中还有另一个类似的流程图,格式类似

\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}

我不明白的是,为什么流程图 1 只能与流程图 2 放在同一章中(在这里编译完美)。每次我尝试将其放在其他地方时,都会出现:

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

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

当然,如果它在一个章节中编译,那么我应该能够将它复制并粘贴到另一个章节中,并且它仍然有效?

编辑:最小示例

\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}

相关内容