0

I have the tikz diagram below and I am trying to change the white nodes into arrows from the parent node. Here is the current diagram

enter image description here

Here is what is a rough sketch of what I am trying to make: enter image description here

I have posted what I have so far below. Any help in making this would be very much appreciated

\documentclass[11pt]{report}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}[level/.style={sibling distance=90mm/#1},scale=0.7]
  \node [circle,draw,fill=gray,scale=0.7] (z){$s_0$}
    child {node [circle,draw,scale=0.7](d){$a_1$}
      child {node [circle,draw,fill=gray,scale=0.6] (a) {$s_1'$} 
      child {node {$\vdots$}}edge from parent node[left=4mm] {\small{$r=10$}}edge from parent node[ fill=white] {\tiny{$1$}}
    }
  }
  child {node [circle,draw,scale=0.7] (a) {$a_2$}
    child {node [circle,draw,fill=gray,scale=0.6] (b) {$s_2'$}
      child {node {$\vdots$}}
      child {node {$\vdots$}}edge from parent node[ above=0.2mm, left=3mm] {\small{$r=20$}}edge from parent node[ fill=white] {\tiny{$0.5$}}
    }
    child {node [circle,draw,fill=gray,scale=0.6] (g) {$s'_3$}
      child {node {$\vdots$}}
        child [grow=right] {node (q) {s'} edge from parent[draw=none]
            child [grow=up] {node (r) {a} edge from parent[draw=none]
            child [grow=up] {node (s) {$s$} edge from parent[draw=none]}}
        }edge from parent node[ above=1mm, right=2mm] {\small{$r=75$}}edge from parent node[ fill=white] {\tiny{$0.5$}}
    }
  }

;



\end{tikzpicture}

\end{document}



3
  • Just replace edge from parent by edge from parent[->] wherever you want an arrow. Please note that forest may be a more convenient option for drawing this.
    – user194703
    Mar 15, 2020 at 17:28
  • It appears I didn't clearly specify the question. I meant that the white node should instead be replaced by the head of an arrow as is shown in the picture
    – KaneM
    Mar 15, 2020 at 18:07
  • Same answer and replace node [circle,draw,scale=0.7](d){$a_1$} by node [coordinate](d){} and likewise for the other node. However, this seems to be some sort of an XY question. If you explain what you are really trying to achieve you may get a perhaps better answer.
    – user194703
    Mar 15, 2020 at 18:12

2 Answers 2

2

You can add ->,level 2/.style={-} to the options of your tikzpicture environment to draw an arrow to the first child level.

\documentclass[11pt]{report}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}[
            level/.style={sibling distance=90mm/#1},
            ->,
            level 2/.style={-},
            scale=0.7]
    \node [circle,draw,fill=gray,scale=0.7] (z){$s_0$}
        child {node [circle,draw,scale=0.7](d){$a_1$}
            child {node [circle,draw,fill=gray,scale=0.6] (a) {$s_1'$} 
            child {node {$\vdots$}}edge from parent node[left=4mm] {\small{$r=10$}}edge from parent node[ fill=white] {\tiny{$1$}}
        }
    }
    child {node [circle,draw,scale=0.7] (a) {$a_2$}
        child {node [circle,draw,fill=gray,scale=0.6] (b) {$s_2'$}
            child {node {$\vdots$}}
            child {node {$\vdots$}}edge from parent node[ above=0.2mm, left=3mm] {\small{$r=20$}}edge from parent node[ fill=white] {\tiny{$0.5$}}
        }
        child {node [circle,draw,fill=gray,scale=0.6] (g) {$s'_3$}
            child {node {$\vdots$}}
                child [grow=right] {node (q) {s'} edge from parent[draw=none]
                    child [grow=up] {node (r) {a} edge from parent[draw=none]
                    child [grow=up] {node (s) {$s$} edge from parent[draw=none]}}
                }edge from parent node[ above=1mm, right=2mm] {\small{$r=75$}}edge from parent node[ fill=white] {\tiny{$0.5$}}
        }
    }

;



\end{tikzpicture}

\end{document}
2
  • It appears I didn't clearly specify the question. I meant that the white node should instead be replaced by the head of an arrow as is shown in the picture
    – KaneM
    Mar 15, 2020 at 18:07
  • You can just remove the corresponding node: node [inner sep = 0pt](d){}
    – luki
    Mar 15, 2020 at 18:15
1
  • As suplement to nice @luki answer (+1)

  • It is not enterally clear, how nodes in white circles should be.

    • just arrow head instead of them, or
    • arrow head with labels containing $a_1$ and $a_2$ respectively?

MWE for the second case:

\documentclass[11pt, border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}[
  arr/.style = {-{Straight Barb[angle=60:2pt 3]}, semithick}, 
    C/.style = {circle, draw, fill=gray!30,
                minimum size=1.6em, inner sep=0pt},
  LBL/.style = {font=\footnotesize},
  lbl/.style = {fill=white, inner sep=2pt, font=\scriptsize},
level/.style = {sibling distance=66mm/#1},
        arr,
level 2/.style={-},
                        ]
\node [C] (z) {$s_0$}
    child {coordinate (a1) 
        child {node [C]     {$s_1'$}
            child {node {$\vdots$}}
                   edge from parent node[LBL, left=4mm] {$r=10$}
                   edge from parent node[lbl] {1}
              }
        }
    child {coordinate (a2)
        child {node [C]     {$s_2'$}
            child {node {$\vdots$}}
            child {node {$\vdots$}}
                   edge from parent node[LBL, left=4mm] {$r=20$}
                   edge from parent node[lbl] {0.5}
              }
        child {node [C] (g) {$s_3'$}
            child {node {$\vdots$}}
            child {node {}
                   edge from parent[draw=none] 
                   }
                   edge from parent node[LBL,right=4mm] {$r=75$}
                   edge from parent node[lbl] {0.5}
              }
        };
\node[left]  at (a1) {$a_1$};  % <---
\node[right] at (a2) {$a_2$};  % <---
\node (s) [LBL, right=6mm] at (g) {$s'$};
\node     [LBL] at (a2 -| s) {$a$};
\node     [LBL] at (z -| s) {$s$};
    \end{tikzpicture}
\end{document}

enter image description here

For the first case you only need to delete code lines marked by % <---:

enter image description here

You must log in to answer this question.

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