0

I have the following tree but I would like to put some probabilities on the branches. Can anybody help me?

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{tikz}
\usepackage{forest}% for version 1
\tikzset{darkp/.style={fill=purple!50!black},
        lightp/.style={fill=purple!50}}

\begin{document} \begin{forest} for tree={ grow'=0, draw, align=c, font=\sffamily, fill=purple, text=white, edge=purple, parent anchor=east, child anchor=west, edge path={% \noexpand\path [\forestoption{edge}] (!u.parent anchor) -- ++(5pt,0) |- (.child anchor)\forestoption{edge label}; } }, highlight/.style={ thick, font=\sffamily\bfseries } [[{Nebulosa rouba a joia} [{Thanos fica sem a joia}, lightp] ] [{Peter Quill \ rouba a joia} [{Kree captura Quill} [{Quill foge sem a joia}] [{Quill foge com a joia} [{Luta com Ronan} [{Vence} [{Joia é entregue a Tropa Nova} [{Thanos consegue a joia} [{Thanos fica com a joia} , darkp] ] ] [{Quill fica com a joia} [{Thanos vence} [{Thanos fica com a joia},darkp] ] [{Quill vence} [{Thanos fica sem a joia},lightp] ] ] [{Quill entrega a joia para Youndu} [{Youndu vence} [{Thanos fica sem a joia},lightp] ] [{Thanos vence} [{Thanos fica com a joia},darkp] ] ] ] ] [{Perde} [{Thanos fica sem a joia},lightp] ] ] [{Quill vende a joia} [{Thanos fica sem a joia},lightp] ] ] ] [{Quill escapa} [{Quill fica com a joia} [{Quill vende a joia} [{Thanos fica sem a joia}, lightp] ] [{Quill vence}] [{Thanos vence} [{Thanos fica com a joia},darkp] ] ] ] ] ] ] ] ] \end{forest} \begin{tikzpicture}[remember picture,overlay] \node[draw,rounded corners=5pt,fill=purple,text=white,font=\sffamily,inner sep=6pt] at (10,8) {Another Event}; \end{tikzpicture} \end{document}

projetmbc
  • 13,315

1 Answers1

1

Sorry, but your question is not entirely clear. Your diagram does not associate (as I see it) with the decision tree, so where (on which branch) you like to have labels with probability values? How labels should be positioned?

So, here is shown a solution which can serve only as starting point. It has:

  • improved code (in comparison to showed in question) for diagram
  • added labels to some few branches, which only show, how you can do this yourself at other branches
\documentclass[border=3mm]{standalone}
\usepackage[edges]{forest}% for forked tree

\begin{document} \begin{forest} for tree = { draw, font=\sffamily, fill=purple, darkp/.style = {fill=purple!60!black}, lightp/.style = {fill=purple!50}, text=white, minimum height=5ex, text width=5.4em, text badly centered, % grow'=0, forked edge,
s sep = 4mm,
l sep = 12mm,
fork sep = 4mm,
anchor = east, child anchor = west, % edge laels /tikz/ELS/.style = {% Edge Label Style pos=0.75, sloped, fill=white, font=\small, text=black, inner sep=2pt}, EL/.style = {edge label={node[ELS]{$#1$}}}, %
edge = purple, } [, coordinate [Nebulosa rouba a joia, EL=p_1 % <--- [Thanos fica sem a joia, lightp] ] [Peter Quill rouba a joia, EL=p_2 % <--- [Kree captura Quill [Quill foge sem a joia, EL=q_1]% <--- [Quill foge com a joia, EL=q_2, % <--- before computing xy={s/.average={s}{siblings}} [Luta com Ronan [Vence [Joia é entregue a Tropa Nova [Thanos consegue a joia [Thanos fica com a joia, darkp] ] ] [Quill fica com a joia, before computing xy={s/.average={s}{siblings}} [Thanos vence [Thanos fica com a joia,darkp] ] [Quill vence [Thanos fica sem a joia,lightp] ] ] [Quill entrega a joia para Youndu [Youndu vence [Thanos fica sem a joia,lightp] ] [Thanos vence [Thanos fica com a joia,darkp] ] ] ] ] [Perde [Thanos fica sem a joia,lightp] ] ] [Quill vende a joia, EL=q_3, % <--- [Thanos fica sem a joia,lightp] ] ] ] [Quill escapa, EL=p_3 % <--- [Quill fica com a joia [Quill vende a joia [Thanos fica sem a joia, lightp] ] [Quill vence, before computing xy={s/.average={s}{siblings}}] [Thanos vence [Thanos fica com a joia,darkp] ] ]
] ] \end{forest} \end{document}

enter image description here

Note: The second image (drawn as TikZ picture) is dropout since it purpose is not clear (to me, at least).

Zarko
  • 296,517