TikZ 编译错误

TikZ 编译错误

在这个 TikZ 中手动的,第 76 页开始,给出了一个简单的代码。在尝试用它编译文档后,

\documentclass[12pt]{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[edge from parent fork down]
\tikzstyle{every node}=[fill=red!30,rounded corners]
\tikzstyle{edge from parent}=[red,-o,thick,draw]
\node {root}
child {node {left}}
child {node {right}
child {node {child}}
child {node {child}}
};
\end{tikzpicture}

\end{document}

我收到此错误:

Package pgfkeys Error: I do not know the key '/tikz/edge from parent fork down' and I am going to ignore it. Perhaps you misspelled it. ...in{tikzpicture}[edge from parent fork down]

也许缺少了某些定义?或者还有什么其他原因?

请注意,同一页面中的第二个示例已成功编译。

答案1

您参考的手册非常过时,但示例也有些不完整。需要两个特定的库:

\usetikzlibrary{trees,arrows}

当前版本手册中的相应代码(第 121 页,针对pgf/TikZ 3.0.1a 版本):

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{trees,arrows}
\begin{document}

\begin{tikzpicture}
[edge from parent fork down, sibling distance=15mm, level distance=15mm,
every node/.style={fill=red!30,rounded corners},
edge from parent/.style={red,-o,thick,draw}]
\node {root}
child {node {left}}
child {node {right}
child {node {child}}
child {node {child}}
};
\end{tikzpicture}
\end{document}

相关内容