1
  1. I am facing problem moving the level of the tree UP. I wanna move the row with yellow boxes and OR gate up, to conserve some space. i tried adding "level distance" in level 3/.style, but that didn't help.

  2. For the text "k/n" in the AND gate, How do I level-shift it?

Code:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{trees,calc,shadings,shapes.gates.logic.US,positioning,arrows, fit}
\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, scale=1.3},
    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},
    tri/.style={regular polygon,regular polygon sides=3,thick,draw=black,fill=black!60,rotate=180, anchor=south, scale=0.5},
% 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=3cm,level distance=1.5cm, growth parent anchor=south,nodes=event},
    level 2/.style={sibling distance=2cm},
    level 3/.style={sibling distance=1.5cm},
    level 4/.style={sibling distance=2cm},
    level 5/.style={},
    level 6/.style={},
    ]
    \node (g1) [event] {System Failure}
            child {node [be, scale=0.2] (e1) {}}
            child[child anchor=east] {node [and, text width=3pt, ] (e2) {k/n}
                {[parent anchor=west,growth parent anchor=west,child anchor=north]
                child {node [sq] (e2a) {}}
                child {node [sq] (e2b) {}}
                child[child anchor=east]  {node (e2c) [or, text width=0pt] {}}
                child {node [sq] (e2d) {}}
                child[sibling distance=3cm] {node [sq] (e2e) {}}
                }
            }
            child {node [be, scale=0.2] (e3) {}}
            child {node [be, scale=0.2] (e4) {}}
            ;
%  Remove what follows if no gates are required
   \node [or]   at (g1.south)   []  {};
%   \node [and]   at (e2.south)   []  {};
% text descriptions go here   
   \node [rotate=360] at ([yshift=-3mm]e1.south)    {Midplane};
   \node [rotate=360] at ([yshift=-3mm]e3.south)    {Cooling};
   \node [rotate=360] at ([yshift=-3mm]e4.south)    {Power domain 1};
   \node [rotate=360] at ([xshift=20mm]e2d.east)    {$\dots$};

\end{tikzpicture}

\end{document}

enter image description here

1 Answer 1

3

Since parent and child structure are not global starting from node (e2) thereafter, so global setting won't work. The space saving wish needs to be adjusted locally from (e2) node. So this solution does the following addition at

edge from parent path={(\tikzparentnode\tikzparentanchor) --  ++(0,-0.5cm) -| (\tikzchildnode\tikzchildanchor)},
level distance=0.8cm           % -0.5cm and 0.8cm can be adjusted to suit one's need.

As to the second concern on label k/n, since the node property is changed by the and gate OP defined. To have property alignment, this solution uses label={center:{k/n}} written in the options, instead of (e2){external label}. Note that the center can be changed to left, right, above, below to suit one's need.

enter image description here

Code

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{trees,calc,shadings,shapes.gates.logic.US,positioning,arrows, fit}
\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, scale=1.3},
    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},
    tri/.style={regular polygon,regular polygon sides=3,thick,draw=black,fill=black!60,rotate=180, anchor=south, scale=0.5},
% 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=3cm,level distance=1.5cm, growth parent anchor=south,nodes=event},
    level 2/.style={sibling distance=2cm},
    level 3/.style={growth parent anchor=west,level distance=-0.5cm, sibling distance=1.5cm},
    level 4/.style={sibling distance=2cm},
    level 5/.style={},
    level 6/.style={},
    ]
    \node (g1) [event] {System Failure}
            child {node [be, scale=0.2] (e1) {}}
            child[child anchor=east] {node [and, text width=3pt,label={center:{k/n}}
] (e2) {}
                {[parent anchor=west,growth parent anchor=west,child anchor=north,
edge from parent path={(\tikzparentnode\tikzparentanchor) --  ++(0,-0.5cm) -| (\tikzchildnode\tikzchildanchor)},
level distance=0.8cm]
                child {node [sq] (e2a) {}}
                child {node [sq] (e2b) {}}
                child[child anchor=east]  {node (e2c) [or, text width=0pt] {}}
                child {node [sq] (e2d) {}}
                child[sibling distance=3cm] {node [sq] (e2e) {}}
                }
            }
            child {node [be, scale=0.2] (e3) {}}
            child {node [be, scale=0.2] (e4) {}}
            ;
%  Remove what follows if no gates are required
   \node [or]   at (g1.south)   []  {};
%   \node [and]   at (e2.south)   []  {};
% text descriptions go here   
   \node [rotate=360] at ([yshift=-3mm]e1.south)    {Midplane};
   \node [rotate=360] at ([yshift=-3mm]e3.south)    {Cooling};
   \node [rotate=360] at ([yshift=-3mm]e4.south)    {Power domain 1};
   \node [rotate=360] at ([xshift=20mm]e2d.east)    {$\dots$};

\end{tikzpicture}

\end{document}

You must log in to answer this question.

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