이진 트리 레이아웃의 노드를 기준으로 노드 위치 지정
Sep 17 2020
그래프 레이아웃을 사용하면 상대 위치가 작동하지 않는다는 것을 알았습니다. 다음 예를 고려하십시오.
\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 Ross Sep 18 2020 at 08:41
당신은 환경으로 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}
1 AbuzarGhafari Sep 18 2020 at 06:18
나무 라이브러리로 만들 수 있습니다. 노드에 노드 이름을 지정하여 노드를 배치 할 수 있습니다.
코드는
\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}
출력은 다음과 같습니다.