1

I would love to have a nice tikz-version of this Word drawing of a tree from an exercise in game theory.

enter image description here

So far I've made the following:

\begin{tikzpicture}[level distance=1.5cm,
    level 1/.style={sibling distance=3cm},
    level 2/.style={sibling distance=1.5cm}]
   \node {$1$}
     child {node {$2$}
      child {node {$(4,1)$}}
      child {node {$(2,1)$}}
    }
     child {node {$2$}
      child {node {$(1,0)$}}
      child {node {$(0,4)$}}
    };
\end{tikzpicture}

But how do add the last details? Thanks.

mas2
  • 13

3 Answers3

3

Off-topic for the tag: Using istgame package with a best alignment for the last trees:

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{istgame}
\usepackage{amsmath}


\begin{document}
\begin{istgame}[scale=1,font=\footnotesize]
\setistDecisionNodeStyle{4pt}
\xtdistance{15mm}{30mm}
\istroot[0](0)[initial node]
<0>{}
\istb{R}[a]{\begin{matrix} 3 & \\ 1 \end{matrix}}[r] 
\endist
\xtdistance
{15mm}{2.5cm}
\istroot(0){$1$}
\istb{L}[al]
\istb{M}[ar]
\endist
\xtdistance{15mm}
{1cm}
\istroot(1)(0-1)<100>{$2$}
\istb{l}[l]{\begin{matrix} \phantom{44}4 & \\ \phantom{44}1 \end{matrix}}
\istb{r}[r]{\begin{matrix} \phantom{44}2 & \\ \phantom{44}1  \end{matrix}}
\endist
\istroot(2)(0-2)<45>
{$2$}
\istb{l}[l]{\begin{matrix} \phantom{44}1 & \\ \phantom{44}0 \end{matrix}}
\istb{r}[r]{\begin{matrix} 
\phantom{44}0 & \\ \phantom{44}4  \end{matrix}}
\endist
\end{istgame}
\end{document}

Another try of using istgame package, but without \phantom things:

\documentclass{article}    
\usepackage{amsmath}
\usepackage{istgame}   
\NewDocumentCommand\vpay{mm}
{\begin{matrix}#1\\#2\end{matrix}}

\begin{document}

\begin{istgame}
\setistDecisionNodeStyle{4pt}
\xtdistance{20mm}{15mm}
\istroot[east](0)
  \istb{R}[a]{\vpay31}[r]
  \endist
\xtdistance{15mm}{30mm}
\istroot(0){1}
  \istb{L}[al]
  \istb{M}[ar]
  \endist
\xtdistance{15mm}{15mm}
\istroot(1)(0-1)<135>{2}
  \istb{\ell}[l]{\vpay41}
  \istb{r}[r]{\vpay21}
  \endist
\istroot(2)(0-2)<45>{2}
  \istb{\ell}[l]{\vpay10}
  \istb{r}[r]{\vpay04}
  \endist
\end{istgame}

\end{document}
I. Cho
  • 2,985
Sebastiano
  • 54,118
2

enter image description here

With use of the forest package:

\documentclass[border=3mm]{standalone}
\usepackage{forest}

\begin{document} \tikzset{ELS/.style={% Edge Label Style font=\footnotesize, inner sep=2pt, anchor=south #1, % label position: "ELS=west" or "ELS=east" pos=0.6}, every label/.style = {font=\small\linespread{0.84}\selectfont,align=center,inner sep=2pt}, } %---------------------------------------------------------------% \begin{forest} for tree={ l sep=13 mm, s sep= 7 mm, where level=2{inner sep=0pt}{circle, fill, outer sep=0pt} }, EL/.style = {% shortenes for edge label, defined as style before typesetting nodes={% edge labels positioning where n=1{% edge label/.wrap value={node[ELS=east]{#1}}% above left }{% edge label/.wrap value={node[ELS=west]{#1}}% above right } } } [,label=1, name=n1 [,label=above left:2, EL=L [, label=below:4\ 1,EL=l] [, label=below:2\ 1,EL=r] ] [,label=above right:2, EL=M [, label=below:1\ 0,EL=l] [, label=below:0\ 4,EL=r] ] ] \draw (n1) -- node[font=\small\sffamily, above] {R} ++ (1.4,0) node[label=east:3\4] {}; \end{forest} \end{document}

Edit: Increased are distance between nodes:

Zarko
  • 296,517
1

Another forest option but without adding too much stuff by hand. It is just one tree, and the edge label is placed on the basis of the actual slope of the edge.

\documentclass[border=3mm]{standalone}
\usepackage[edges]{forest}
\tikzset{lbl/.style={circle,fill,inner sep=1.5pt,label=above:#1},
/forest/el/.style={edge label={
let \p1=($(.child anchor)-(!u.parent anchor)$),\n1={atan2(\y1,\x1)},
\n2={ifthenelse(cos(\n1)<0,\n1+90,\n1-90)} in
node[pos=1/2,anchor=\n2,font=\sffamily]{#1}}}}

\begin{document}

\begin{forest}
for tree={grow=south,
    l sep+=2em,
    s sep+=1em,
    edge+={thick},
    font=\sffamily
  }
[,label=above:3,label=below:1,grow'=west
 [,lbl=1,el=R
  [,lbl=2,el=L
   [4,label=below:1,el=l]
   [2,label=below:0,el=r]
  ]
  [,lbl=2,el=M
   [1,label=below:0,el=l]
   [0,label=below:4,el=r]
  ]
 ]
]
\end{forest}
\end{document}

enter image description here