
그래프 레이아웃을 사용하면 상대 위치 지정이 작동하지 않는다는 것을 알았습니다. 다음 예를 고려하십시오.
\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
나무 라이브러리를 사용하여 이를 만들 수 있습니다. 노드에 노드 이름을 지정하여 노드 위치를 지정할 수 있습니다.
코드는
\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}
출력은 다음과 같습니다