Below=of 无法理解 tikz 定位

Below=of 无法理解 tikz 定位

我正在尝试使用 TikZ,但无法理解节点的相对定位。我正在使用今天下载的 MacTex 安装。此代码是从 TikZ 手册复制而来的,但无法编译:

\documentclass{article}

\usepackage{tikz}
\begin{document}

\begin{figure}[hp]
  \centering
\begin{tikzpicture}
 [place/.style={circle,draw=blue!50,fill=blue!20,thick,inner sep=0pt,minimum size=6mm},
 transition/.style={rectangle,draw=black!50,fill=black!20,thick,inner sep=0pt,minimum size=4mm}]

 \node[place] (waiting) {};
  \node[place] (critical) [below=of waiting] {};
\end{tikzpicture}


  \end{tikzpicture}
  \caption{Always include a caption before the label}
  \label{fig:MergeIdeal}
\end{figure}

\end{document}

当我尝试使用 进行编译时pdflatex -halt-on-error problem.tex,我得到了这个输出

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./problem.tex
LaTeX2e <2015/01/01>
Babel <3.9l> and hyphenation patterns for 79 languages loaded.
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2015/texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/pgf/utilities/pgfrcs.sty
(/usr/local/texlive/2015/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.te
x
(/usr/local/texlive/2015/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-li
sts.tex))

<... many more files opened...>

! Package PGF Math Error: Unknown function `of' (in 'of waiting').

See the PGF Math package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.15   \node[place] (critical) [below=of waiting]
                                                  {};
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on problem.log.

Tikz.sty 的版权是 2006,所以我可能有一个不支持此语法的旧版本,所以我从http://sourceforge.net/projects/pgf/files/,这是 2013 年的。这给出了同样的错误(我确实检查过 tikz.sty 是否从新位置加载)。

我在这里做错了什么?

答案1

您需要该positioning库;添加到序言中\usetikzlibrary{positioning}

你的例子:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{figure}[hp]
\centering
\begin{tikzpicture}
 [place/.style={circle,draw=blue!50,fill=blue!20,thick,inner sep=0pt,minimum size=6mm},
 transition/.style={rectangle,draw=black!50,fill=black!20,thick,inner sep=0pt,minimum size=4mm}]

 \node[place] (waiting) {};
  \node[place] (critical) [below=of waiting] {};
\end{tikzpicture}
\caption{A test figure}
\label{fig:MergeIdeal}
\end{figure}

\end{document}

结果:

在此处输入图片描述

相关内容