5

I am trying to draw the following tree: Tree

Below is the code I have so far, and I don't know how to do it accurately. Also, I am using "forest." Would it be better to use Tikz?

\documentclass{article} 
\usepackage[edges]{forest}
\usepackage[outline]{contour}
\usetikzlibrary{fit,shapes.misc,arrows.meta,positioning}

\begin{document}
\begin{forest}
for tree={s sep=0.1cm,l sep=1.2cm,font=\scriptsize,
where n children=0{align=center,draw,edge={thick,-{Circle}}}            {circle,fill,inner sep=0pt,minimum size=2mm},
where n=1{edge label={node[midway,above left=0pt,font=\scriptsize]{S}}}    {edge
label={node[midway,above right=0pt,font=\scriptsize]{E}}},
edge={thick}
}
  [,alias=T
   [
    [,alias=L
     [
      [{$B-C$ \\ $0$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $R-L$}]
     ]
    ]
    [
     [
      [{$B-C$ \\ $0$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $R-L$}]
     ]
    ]
   ]
   [
    [
     [
      [{$B-C$ \\ $\bar{R}$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $R-L$}]
     ]
    ]
    [,alias=R
     [
      [{$B-C$ \\ $\bar{R}$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $R-L$}]
     ]
    ]
   ]
  ]
\node[draw,dashed,rounded rectangle,fit=(L) (R)]{};  
\node[left=1mm of very left,align=right,font=\scriptsize]{Nature};
\end{forest}

\end{document}
  • Does the code run through on your machine without errors? On my TeXLive 2019 installation I get ! Missing number, treated as zero. <to be read again> \forest@id@of@very left when I compile it with pdflatex. Apart from that I would like to ask which concrete changes you wish to achieve. – marmot Jun 24 at 1:13
  • forest is TikZ. It just provides a much better syntax for tree drawing. So it is a good choice and much better than the basic TikZ methods. There is also the istgame package which uses a very different syntax but is specifically designed for game trees. – Alan Munn Jun 24 at 1:14
  • You can get rid of the error when you replace the very last \node command by \node[above=1mm of T,font=\scriptsize]{Nature};. – marmot Jun 24 at 1:19
8

I cannot answer the question TikZ or forest because, as Alan points out, forest is based on TikZ. The only thing I can do is to add the bent dashed fit around two of your nodes. This is done with a style rconnect

\draw[dashed] let \p1=($(F1.north)-(F1.center)$) in
 [/tikz/rconnect/radius=\y1] [rconnect=LL and RR];

where the let ... in is to make sure that the dimensions match those of your fit nodes. (You can add the Nature node using a label, which also fixes the minor error I got when running your code.)

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage[edges]{forest}
\usepackage[outline]{contour}
\usetikzlibrary{fit,shapes.misc,arrows.meta,positioning}
\tikzset{rconnect/.style args={#1 and #2}{insert path={
($(#1)+(270+\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})$) 
arc(270+\pgfkeysvalueof{/tikz/rconnect/angle}:90+\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})
to[out=\pgfkeysvalueof{/tikz/rconnect/angle},in=180-\pgfkeysvalueof{/tikz/rconnect/angle}] 
($(#2)+(90-\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})$) 
arc(90-\pgfkeysvalueof{/tikz/rconnect/angle}:-90-\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})
to[in=\pgfkeysvalueof{/tikz/rconnect/angle},out=180-\pgfkeysvalueof{/tikz/rconnect/angle}] 
cycle}},rconnect/.cd,radius/.initial=6.5pt,angle/.initial=-12}
\begin{document}
\begin{forest}
for tree={s sep=0.1cm,l sep=1.2cm,font=\scriptsize,
where n children=0{align=center,draw,edge={thick,-{Circle}}}            {circle,fill,inner sep=0pt,minimum size=2mm},
where n=1{edge label={node[midway,above left=0pt,font=\scriptsize]{S}}}    {edge
label={node[midway,above right=0pt,font=\scriptsize]{E}}},
edge={thick}
}
  [,label=above:Nature,alias=T
   [,alias=L
   [,alias=LL
     [
      [{$B-C$ \\ $0$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $R-L$}]
     ]
    ]
    [,alias=LR
     [
      [{$B-C$ \\ $0$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $R-L$}]
     ]
    ]
   ]
   [,alias=R
    [,alias=RL
     [
      [{$B-C$ \\ $\bar{R}$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $R-L$}]
     ]
    ]
    [,alias=RR
     [
      [{$B-C$ \\ $\bar{R}$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $R-L$}]
     ]
    ]
   ]
  ]
\node[draw,dashed,rounded rectangle,fit=(L) (R)] (F1){};  
\node[draw,dashed,rounded rectangle,fit=(LR) (RL)]{};  
\draw[dashed] let \p1=($(F1.north)-(F1.center)$) in
 [/tikz/rconnect/radius=\y1] [rconnect=LL and RR];
\end{forest}
\end{document}

enter image description here

1

Another solution to use the istgame package:

enter image description here

\documentclass{standalone}

\usepackage{amsmath}
\usepackage{makecell}

\usepackage{istgame}

\NewDocumentCommand\mact{m}
{\makecell[c]{#1}}
\NewDocumentCommand\mpay{m}
{\begin{matrix}#1\end{matrix}}

\begin{document}

\begin{istgame}[font=\footnotesize]
\setistmathTF*001
\xtShowEndPoints
% top part
\xtdistance{25mm}{120mm}
\istroot(0)[chance node]{Nature}
  \istb{\mact{$R=O$\\cooperative\\partner}}[al]
  \istb{\mact{$R=\bar R$\\noncooperative\\partner}}[ar]  \endist
\xtdistance{25mm}{50mm}
\istroot(A)(0-1)%<180>{Minister}
  \istb{\mact{Introduce\\first proposal}}[l]  \endist
\istroot(B)(0-2)%<0>{Minister}
  \istb{\mact{Introduce\\first proposal}}[r]  \endist
% left part
\xtdistance{25mm}{60mm}
\istroot(A0)(A-1)<180>{Partner}
  \istb{Scrutinize}[l]  \istb{Endorse}[r]  \endist
\xtdistance{25mm}{30mm}
\istroot(A1)(A0-1)<0>{$B-C,O$}
  \istb{\mact{Introduce\\second\\proposal}}[al]  \istb{Delay}[ar]  \endist
\istroot(A2)(A0-2)<180>{$B,X$}
  \istb{\mact{Introduce\\second\\proposal}}[al]  \istb{Delay}[ar]  \endist
\xtdistance{25mm}{15mm}
\istroot(A3)(A1-1)<180>{Partner}
  \istb{Scrut.}[l]{B-C,O}        \istb{Endorse}[r]{B,X}         \endist
\istroot(A4)(A1-2)<0>{Partner}
  \istb{S}[l]{\mpay{B-L,\\R-L}}  \istb{E}[r]{\mpay{B-L,\\R-L}}  \endist
\istroot(A5)(A2-1)<0>{Partner}
  \istb{S}[l]{B-C,O}             \istb{E}[r]{B,X}               \endist
\istroot(A6)(A2-2)<0>{Partner}
  \istb{S}[l]{\mpay{B-L,\\R-L}}  \istb{E}[r]{\mpay{B-L,\\R-L}}  \endist
% right part
\xtdistance{25mm}{60mm}
\istroot(B0)(B-1)<180>{Partner}
  \istb{Scrutinize}[l]  \istb{Endorse}[r]  \endist
\xtdistance{25mm}{30mm}
\istroot(B1)(B0-1)<0>{$B-C,\bar R$}
  \istb{\mact{Introduce\\second\\proposal}}[al]  \istb{Delay}[ar]  \endist
\istroot(B2)(B0-2)<180>{$B,X$}
  \istb{\mact{Introduce\\second\\proposal}}[al]  \istb{Delay}[ar]  \endist
\xtdistance{25mm}{15mm}
\istroot(B3)(B1-1)<180>{Partner}
  \istb{Scrut.}[l]{B-C,\bar R}   \istb{Endorse}[r]{B,X}         \endist
\istroot(B4)(B1-2)<0>{Partner}
  \istb{S}[l]{\mpay{B-L,\\R-L}}  \istb{E}[r]{\mpay{B-L,\\R-L}}  \endist
\istroot(B5)(B2-1)<0>{Partner}
  \istb{S}[l]{B-C,\bar R}        \istb{E}[r]{B,X}               \endist
\istroot(B6)(B2-2)<0>{Partner}
  \istb{S}[l]{\mpay{B-L,\\R-L}}  \istb{E}[r]{\mpay{B-L,\\R-L}}  \endist
% information sets
\xtInfosetO(A)(B){Minister}
\xtCInfosetO(A1)!.35!(B1)<1.15>{Minister}
\xtCInfosetO(A2)!.65!(B2)<1.15>{Minister}
\end{istgame}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.