使用 TikZ 的故障树:在多个级别绘制子树

使用 TikZ 的故障树:在多个级别绘制子树

在 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 子树的位置。这是通过使用节点[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}

在此处输入图片描述

相关内容