4

I am trying to modify the Fault tree e.g. from Tikz where the nodes are the objects like gates instead of text boxes, and would even elimiate text boxes from few paths if possible. This is my code so far.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{trees,calc,shadings,shapes.gates.logic.US,positioning,arrows}
\usetikzlibrary{shapes,snakes}

\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},
    tr/.style={buffer gate US,thick,draw,fill=purple!60,rotate=90,
        anchor=east,minimum width=0.8cm},
    sq/.style={regular polygon,regular polygon sides=4,thick,draw,fill=orange!60,anchor=north, scale=0.2},
% 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},
    event2/.style={rectangle,draw=white, fill=white,},
    and2/.style={and gate US,draw,fill=red!60,rotate=90, scale=0.5 },
% 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=4cm,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] {System Failure}
            child {node (e1) {Midplane}}
            child {node [event] (e2) {k/n}
                child {node [sq] (e2a) {1}}
                child {node [sq] (e2b) {2}}
                child[level distance=20mm] {node (e2c) [or, scale=0.4] {}
                    child {node [sq] (e2c1) {x}}
                    child {node [sq] (e2c2) {y}}
                }
                child {node [sq] (e2d) {4}}
            }
            child {node (e3) {Cooling}}
            child {node (e4) {Power domain 1}}
            ;
%  Remove what follows if no gates are required
   \node [or]   at (g1.south)   []  {};
   \node [be]   at (e1.south)   []  {};
   \node [and]   at (e2.south)   []  {};
   \node [be]   at (e3.south)   {};
   \node [be]   at (e4.south)   {};
\end{tikzpicture}

\end{document}

As you can see, i am clearly struggling with the blue OR gate in the middle. Where am I going wrong?

2 Answers 2

3

Just to explain what is going wrong in your code:

The problem is your definition of edge from parent path

edge from parent path={(\tikzparentnode.south) -- ++(0,-1.05cm)-| (\tikzchildnode.north)}

But as a result of the rotation in or/.style the north anchor of or nodes is on their left side and the south anchor is on their right side. (See How to manage rotated rectangles positioning) Therefore you have to change the child anchor, the parent anchor and also the growth parent anchor for or childs in the tree.

If you use

edge from parent path={(\tikzparentnode\tikzparentanchor) -- 
    ++(0,-1.05cm)-| (\tikzchildnode\tikzchildanchor)},
parent anchor=south,
child anchor=north,

you can change the parent anchor and the child anchor inside the tree.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{trees,calc,shadings,shapes.gates.logic.US,positioning,arrows}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}
 [
% Gates and symbols style
    and/.style={and gate US,thick,draw=black,fill=red!60,rotate=90,
        anchor=east,xshift=-1mm},
    or/.style={or gate US,thick,draw=black,fill=blue!60,rotate=90,
        anchor=east,xshift=-1mm},
    be/.style={circle,thick,draw=black,fill=green!60,anchor=north,
        minimum width=0.7cm},
    tr/.style={buffer gate US,thick,draw=black,fill=purple!60,rotate=90,
        anchor=east,minimum width=0.8cm},
    sq/.style={regular polygon,regular polygon sides=4,thick,draw=black,fill=orange!60,anchor=north, scale=0.2},
% Label style
    label distance=3mm,  every label/.style={blue},
% Event style
    event/.style={rectangle,thick,draw=black,fill=yellow!20,text width=2cm, text centered,font=\sffamily,anchor=north},
    event2/.style={rectangle,draw=white, fill=white,},
    and2/.style={and gate US,draw,fill=red!60,rotate=90, scale=0.5 },
% Children and edges style
    edge from parent/.style={very thick,draw=black!70},
    edge from parent path={(\tikzparentnode\tikzparentanchor) --  ++(0,-1.05cm) -| (\tikzchildnode\tikzchildanchor)},
    parent anchor=south,
    child anchor=north,
    level 1/.style={sibling distance=4cm,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}
    ]
    \node (g1) [event] {System Failure}
            child {node (e1) {Midplane}}
            child {node [event] (e2) {k/n}
                child {node [sq] (e2a) {1}}
                child {node [sq] (e2b) {2}}
                child[child anchor=east] {node (e2c) [or, text width=0pt] {}
                    {[parent anchor=west,growth parent anchor=west,child anchor=north]
                      child {node [sq] (e2c1) {x}}
                      child {node [sq] (e2c2) {y}}}
                }
                child {node [sq] (e2d) {4}}
            }
            child {node (e3) {Cooling}}
            child {node (e4) {Power domain 1}}
            ;
%  Remove what follows if no gates are required
   \node [or]   at (g1.south)   []  {};
   \node [be]   at (e1.south)   []  {};
   \node [and]   at (e2.south)   []  {};
   \node [be]   at (e3.south)   {};
   \node [be]   at (e4.south)   {};
\end{tikzpicture}

\end{document}

enter image description here

4

Based on the code displayed, all gates are put at where they are by a \node commands listed at the end of the code. Thus the (e2c) node is a rectange node as its neighbours. So you can not simply put a OR in the option of that node, which results in what the OP has shown. A way to work around is to change (e2c) node into coordinate so that it has no shape and then put the OR by an extra node command as shown below where yshift is used to adjust the position of the OR gate.

enter image description here

Code

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{trees,calc,shadings,shapes.gates.logic.US,positioning,arrows}
\usetikzlibrary{shapes,snakes}

\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},
    tr/.style={buffer gate US,thick,draw,fill=purple!60,rotate=90,
        anchor=east,minimum width=0.8cm},
    sq/.style={regular polygon,regular polygon sides=4,thick,draw,fill=orange!60,anchor=north, scale=0.2},
% 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},
    event2/.style={rectangle,draw=white, fill=white,},
    and2/.style={and gate US,draw,fill=red!60,rotate=90, scale=0.5 },
% 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=4cm,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] {System Failure}
            child {node (e1) {Midplane}}
            child {node [event] (e2) {k/n}
                child {node [sq] (e2a) {1}}
                child {node [sq] (e2b) {2}}
                child[level distance=20mm] {node (e2c) [coordinate,scale=0.4] {}  % change the node to coordinate property, the default is a rectangle.
                    child {node [sq] (e2c1) {x}}
                    child {node [sq] (e2c2) {y}}
                }
                child {node [sq] (e2d) {4}}
            }
            child {node (e3) {Cooling}}
            child {node (e4) {Power domain 1}}
            ;
%  Remove what follows if no gates are required
   \node [or]   at ([yshift=0.5cm]e2c.south) []  {};     % added one line here
   \node [or]   at (g1.south)   []  {};
   \node [be]   at (e1.south)   []  {};
   \node [and]  at (e2.south)   []  {};
   \node [be]   at (e3.south)   {};
   \node [be]   at (e4.south)   {};
\end{tikzpicture}

\end{document}
2
  • The shape of the (e2c) node does not depend on the neighbour shapes. It is a or gate US and not a rectangle. The real cause is the rotation.
    – esdd
    Commented May 29, 2014 at 18:27
  • OK, if you remove the OR and compile, it will give you a rectangle of event style. That is what I meant to say.
    – Jesse
    Commented May 29, 2014 at 20:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .