
グラフ レイアウトを使用する場合、相対的な配置は機能しないことがわかりました。次の例を検討してください。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{
graphdrawing
, graphs
, positioning
}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}[binary tree layout]
\graph {
n0 -> {n1, n2};
};
\node [left = of n0] {left of n0};
\end{tikzpicture}
\end{document}
次のような予期しない出力が生成されます。
配置に関するほとんどすべてのことは機能しません。at (n0.center)
最後のノードは同じ場所に配置されます。 グラフ内のノードを基準にしてノードを配置するにはどうすればよいでしょうか?
答え1
binary tree layout
環境に渡しています。これを次のようtikzpicture
に に渡されるオプションに移動すると、コードは機能します。\graph
\graph[binary tree layout]
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{
graphdrawing
, graphs
, positioning
}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}%[binary tree layout]
\graph[binary tree layout] {
n0 -> {n1, n2};
};
\node[left= of n0] {left of n0};
\end{tikzpicture}
\end{document}
答え2
これは、trees ライブラリを使用して作成できます。ノードにノードの名前を付けることで、ノードを配置できます。
コードは
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\begin{tikzpicture}[level distance=1.5cm,
level 1/.style={sibling distance=3cm}]
\node (n0) {n0}
child {node (n1) {n1}}
child {node (n2) {n2}
};
\node [left of=n0, xshift=-1cm] {left of n0};
\end{tikzpicture}
\end{document}
出力は次のようになります