![TikZ를 사용한 오류 트리: 여러 수준에서 하위 트리 그리기](https://rvso.com/image/286350/TikZ%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%9C%20%EC%98%A4%EB%A5%98%20%ED%8A%B8%EB%A6%AC%3A%20%EC%97%AC%EB%9F%AC%20%EC%88%98%EC%A4%80%EC%97%90%EC%84%9C%20%ED%95%98%EC%9C%84%20%ED%8A%B8%EB%A6%AC%20%EA%B7%B8%EB%A6%AC%EA%B8%B0.png)
TiKZ 예의 오류 트리 행(http://www.texample.net/tikz/examples/fault-tree/), 다음과 같은 오류 트리를 만들었습니다.
\node (g1) [event] {Project fails \\ E0}
child {node (e1) {No legal permit \\(E1)}
child {node (e11) {No legal permit A \\ (E11)}}
child {node (e12) {No legal permit B \\ (E12)}}
child {node (e13) {No legal permit C \\ (E13)}}
}
child {node (e2) {No financing \\(E2)}
child {node (e21) {No financing A \\ (E21)}}
child {node (e22) {No financing B \\ (E22)}}
child {node (e23) {No financing C \\ (E23)}}
}
child {node (e3) {No collaboration}
child {node (e31) {Low incentive}}
child {node (e32) {Low trust}}
};
그러나 트리의 노드는 서로 겹칩니다. 노드 사이의 거리를 줄이려고 노력했지만 이 경우에는 그렇게 우아해 보이지 않습니다. E2 하위 트리가 E1 하위 트리보다 낮은 수준에 있을 수 있는 방법이 있습니까?
답변1
이것이 당신이 쫓고 있는 것입니까? 귀하의 코드가 귀하가 게시한 이미지를 반영하지 않는 것 같습니다. 이 솔루션은 원하는 이미지를 생성하고 E2 하위 트리를 E1 하위 트리보다 낮은 위치로 이동하려고 시도했습니다. 이는 node.js [level distance=xx]
의 옵션을 사용하여 달성됩니다 e2
.
child[level distance=70mm] {node (e2) {No financing \\(E2)}
E3 하위 트리가 약간 왼쪽으로 이동하려는 경우에도 동일한 아이디어가 적용됩니다. 하지만 [sibling distance=xx]
여기서 사용되는
child[sibling distance=30mm] {node (e3) {No collaboration}
게이트가 필요하지 않으면 마지막 부분에서 코드를 제거하십시오.
암호
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{trees,calc,shadings,shapes.gates.logic.US,positioning,arrows}
\begin{document}
\begin{tikzpicture}
[
% Gates and symbols style
and/.style={and gate US,thick,draw,fill=red!60,rotate=90,
anchor=east,xshift=-1mm},
or/.style={or gate US,thick,draw,fill=blue!60,rotate=90,
anchor=east,xshift=-1mm},
be/.style={circle,thick,draw,fill=green!60,anchor=north,
minimum width=0.7cm},
% Label style
label distance=3mm, every label/.style={blue},
% Event style
event/.style={rectangle,thick,draw,fill=yellow!20,text width=2cm, text centered,font=\sffamily,anchor=north},
% Children and edges style
edge from parent/.style={very thick,draw=black!70},
edge from parent path={(\tikzparentnode.south) -- ++(0,-1.05cm)-| (\tikzchildnode.north)},
level 1/.style={sibling distance=5cm,level distance=1.5cm, growth parent anchor=south,nodes=event},
level 2/.style={sibling distance=3cm, level distance=2cm},
level 3/.style={sibling distance=3cm},
level 4/.style={sibling distance=3cm}
]
%% Draw events and edges
\node (g1) [event] {Project fails \\ E0}
child{node (e1) {No legal permit \\(E1)}
child {node (e11) {No legal permit A \\ (E11)}}
child {node (e12) {No legal permit B \\ (E12)}}
child {node (e13) {No legal permit C \\ (E13)}}
}
child[level distance=70mm] {node (e2) {No financing \\(E2)}
child {node (e21) {No financing A \\ (E21)}}
child {node (e22) {No financing B \\ (E22)}}
child {node (e23) {No financing C \\ (E23)}}
}
child {node (e3) {No collaboration\\ (E3)}
child {node (e31) {Low incentive\\ (E31)}}
child {node (e32) {Low trust\\ (E32)}}
};
% Remove what follows if no gates are required
\node [or] at (g1.south) [] {};
\node [or] at (e1.south) [] {};
\node [or] at (e2.south) [] {};
\node [and] at ([yshift=1mm]e21.south) [] {};
\node [and] at ([yshift=1mm]e22.south) [] {};
\node [and] at ([yshift=1mm]e23.south) [] {};
\node [and] at (e3.south) [] {};
\node [be] at (e11.south) [] {};
\node [be] at (e12.south) [] {};
\node [be] at (e13.south) [] {};
\node [be] at (e31.south) [] {};
\node [be] at (e32.south) [] {};
\end{tikzpicture}
\end{document}