7

Does anyone know how to prevent the branches of a decision tree from converging on each other? This is with Tikz - I've tried tweaking the sibling distance and things like that, but two of the branches at the end converge so that the final values are illegible.

Secondly, does anyone know how to put in a dashed line between the two square "choice" siblings? To indicate an information set.

\documentclass{article}
\usepackage{tikz}
\tikzset{
    choice/.style = {shape=rectangle, draw, align=center, color=black, fill=black, font=\normalsize},
    chance/.style = {shape=circle, draw, align=center, color=black, fill=black, font=\normalsize},
    root/.style = {choice, font=\normalsize, color=black},
    outcome/.style = {shape=rectangle, draw=white, align=center, font=\tiny, parent anchor=left},
}

\begin{figure}[H]
\centering
\begin{tikzpicture}
  [
    grow = right,
    sibling distance = 6em,
    level distance = 8em,
    edge from parent/.style = {draw, -latex},
    every node/.style = {font=\normalsize},
    sloped
  ]
\node [root] {}
    child {node [outcome, label=right:{\$30}] {}
        edge from parent node [below] {}}
    child {node [choice] {}
        child {node [chance] {}
        child {node [choice] {}
            child {node [outcome, label=right:{\$10}]{}}
            child {node[outcome, label=right:{\$100}]{}}
            edge from parent node [below] {.5}}
        child {node [choice]{}
            child {node [outcome, label=right:{\$45}]{}}
            child {node [outcome, label=right:{\$55}]{}}
            edge from parent node [above] {.5}}
        edge from parent node [below] {}}
        child {node [outcome, label=right:{\$25}]{}
            edge from parent node [above] {}}
                    edge from parent node [above] {}};
\end{tikzpicture}
\caption{Sample Decision Tree} \label{fig: Sample}
\end{figure}

2 Answers 2

4

I use yshift option to change the position of the nodes, to avoid overlapping.

I give two choice nodes some names (a and b) and draw a dashed line as usual.

Code:

\documentclass[tikz]{standalone}
\tikzset{
    choice/.style = {shape=rectangle, draw, align=center, color=black, fill=black, font=\normalsize},
    chance/.style = {shape=circle, draw, align=center, color=black, fill=black, font=\normalsize},
    root/.style = {choice, font=\normalsize, color=black},
    outcome/.style = {shape=rectangle, draw=white, align=center, font=\tiny, parent anchor=left},
}

\begin{document}
\begin{tikzpicture}
  [
    grow = right,
    sibling distance = 6em,
    level distance = 8em,
    edge from parent/.style = {draw, -latex},
    every node/.style = {font=\normalsize},
    sloped
  ]
\node [root] {}
    child {node [outcome, label=right:{\$30}] {}
        edge from parent node [below] {}}
    child {node [choice] {}
        child {node [chance] {}
        child {node [choice] (a) {}
            child {node [outcome, label=right:{\$10}]{}}
            child {node[yshift=-2em,outcome, label=right:{\$100}]{}}
            edge from parent node [below] {.5}}
        child {node [choice] (b) {}
            child {node [yshift=2em,outcome, label=right:{\$45}]{}}
            child {node [outcome, label=right:{\$55}]{}}
            edge from parent node [above] {.5}}
        edge from parent node [below] {}}
        child {node [outcome, label=right:{\$25}]{}
            edge from parent node [above] {}}
                    edge from parent node [above] {}};
\draw[dashed] (a)--(b);
\end{tikzpicture}
\end{document}

enter image description here

4

I would like to recommend forest, where the syntax is simpler and you do not have to worry about these things.

\documentclass{article}
\usepackage[edges]{forest}
\tikzset{
    choice/.style = {shape=rectangle, draw, align=center, color=black, fill=black},
    chance/.style = {shape=circle, draw, align=center, color=black, fill=black},
    root/.style = {choice, font=\normalsize, color=black},
    outcome/.style = {shape=rectangle, draw=white, align=center, font=\tiny, parent anchor=left},
}

\begin{document}
\begin{forest}
for tree={grow'=east,edge={-latex},l+=1cm}
[,root
 [,choice
  [\$25]
  [,chance
   [,choice,edge label={node[midway,above,sloped]{.5}}
    [\$55]
    [\$45]
   ]
   [,choice,edge label={node[midway,below,sloped]{.5}}
    [\$100]
    [\$10]
   ]
  ]
 ]
 [\$30]
]
\end{forest}
\end{document}

enter image description here

You must log in to answer this question.

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