2

I am trying to create such a graph

unconected network

However, this is the result of my try:

subraphs in latex

\begin{tikzpicture}[nodes={draw, circle}, ->]
    \node{B1 } 
        child { node [label=left:\tiny{$\{t_2^d, s_2^d \}$}] (B2) {B2} 
            child {node [label=left:\tiny{$\{t_4^d, s_4^d \}$}] {B4} }
            child { node [label=below:\tiny{$\{t_5^d, s_5^d \}$}] {B5} }  
        }
        child { node [label=right:\tiny{$\{t_3^d, s_3^d \}$}] (B3) {B3} 
            child [ missing ]
            child { node [label=right:\tiny{$\{t_6^d, s_6^d \}$}] {B6} 
                child { node [label=right:\tiny{$\{t_7^d, s_7^d \}$}] {B7}}
            }  
        };
        \node[right = 100pt of B3, label={[label distance=2pt]-90:\tiny{$\{t_6^d, s_6^d \}$}}] (B8) {B8}; \end{tikzpicture}

Main issues:

  • How to annotate parent node

  • How to have two parent nodes for one node.

  • How to change distances between nodes to put annotations at the right side of each node.

1 Answer 1

3

You cannot have two parents for a child.1 Actually, I'd use a matrix for this. The labels can be added via overlay (which is why one has to add \path (l-7.east); to get the correct bounding box).

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[b/.style={circle,draw,execute at begin node={$b_{#1}$},
    alias=b-#1,label={[rectangle,draw=none,overlay,alias=l-#1]right:{$[s_{#1},t_{#1}]$}}}]
\node[matrix of nodes,column sep=1em,row sep=2em]{
 & & |[b=1]|& & |[b=2]| & & &|[b=7]|\\
 &  |[b=3]|& & |[b=4]| &  & &|[b=8]| &\\
   |[b=5]|& & |[b=6]| &  & & &|[b=9]| &\\
};
\path[-stealth] foreach \X/\Y in {1/3,3/5,3/6,1/4,2/4} {(b-\X) edge (b-\Y)};
\draw (b-8) -- (b-9);
\path (l-7.east); %<- for the bounding box
\end{tikzpicture}
\end{document}

enter image description here

1This does not exclude the possibility to add a second parent by hand.

2
  • Thank you so much. When I changed '(b-8) -- (b-9)' to '(b-8) -> (b-9)', it didn't generate arrow from b8 to b9.
    – Hadij
    Jun 11, 2020 at 18:55
  • 2
    @Hadij The syntax is \draw[-stealth] (b-8) -- (b-9);, but you can simply add 8/9 to the list {1/3,3/5,3/6,1/4,2/4}, i.e. use {1/3,3/5,3/6,1/4,2/4,8/9} to add the arrow.
    – user194703
    Jun 11, 2020 at 18:58

You must log in to answer this question.

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