Small corrections needed for game tree
The missing text has been added as label
s to the nodes. I defined a style addlabel
for convenience. The amsmath
package is added for the \text
macro.
For the missing lines, I use the syntax of the calc
library to draw a line relative to the n0
node, and I add a coordinate
at each end of that line (l1
and l2
). The next two lines are drawn with perpendicular coordinates, e.g. (l1 |- n2)
is the point that has the x-coordinate of l1
and the y-coordinate of n2
. This makes it easy to draw the lines of the same length.
I also removed the xcolor
package, as that is already loaded by tikz
, and moved the dvipsnames
option to the documentclass.
I don't know where \floatfoot
comes from, so that is commented out, and the extra \end{tikzpicture}
you had is removed. I also commented the \linespread
, do you really want that? (Personally I'd remove it.)
\documentclass[12pt,twoside,dvipsnames]{book}%{book}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
font = \footnotesize,
edge from parent/.style = {draw ,thin},
SN/.style = {%solid node
circle, inner sep=1.2 ,fill=blue,
},
HN/.style = {%hollow node
circle, inner sep=1.2, draw=blue,
},
addlabel/.style={label={[align=center]below:#1}},
level distance = 25mm,
level 1/.style = {sibling distance=50mm},
level 2/.style = {sibling distance=40mm}
]
%---
%\linespread{0.8}
%-------
\node (n0) [HN] {}
child{ node (n1) [SN,addlabel={$\pi_1=\text{equation 1}$\\$u_1=\text{utility 1}$}] {}
edge from parent node[left]{$n_c$ buy}
}
child{ node (n2) [SN] {}
child{node[HN,addlabel={$\pi_2=\text{equation 2}$\\$u_2=\text{utility 2}$}] {}
edge from parent node[left]{$1-n_c$ buy}}
child{node[HN,addlabel={0\\0}] (n3) {}
edge from parent node[right]{not buy}}
edge from parent node[right]{not buy}
};
\draw[<-,shorten <=1pt]
(n0) -- + (2,1) node[right,align=left] {Entrepreneur\\
sets $P_c$ };
\draw[<-,shorten <=1pt]
(n2) -- + (2,1) node[right,align=left] {Entrepreneur\\
sets $P_r$ };
\draw [dotted] ($(n0.center)+(-4cm,0)$) coordinate (l1) -- ($(n0.center) + (6cm,0)$) coordinate (l2) node[right] {$t=0$};
\draw [dotted] (l1 |- n2) -- (l2 |- n2) node[right] {$t=1$};
\draw [dotted] (l1 |- n3) -- (l2 |- n3) node[right] {$t=3$};
\end{tikzpicture}
\caption{Timing of game}
\label{Testing label}
% \floatfoot{\textit{Source}: Own illustration}
\end{figure}
\end{document}
A solution with forest
Code
\documentclass[12pt,twoside]{book}%{book}
\usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}
\usepackage{forest,mathtools}
\forestset{
declare toks={elo}{}, % Edge Label Options
anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
dot/.style={tikz={\draw[blue,#1] (.child anchor) circle[radius=1.5pt];}},
decision edge label/.style n args=3{
edge label/.expanded={node[midway,auto=#1,anchor=#2,\forestoption{elo}]{\strut\unexpanded{#3}}}
},
decision/.style={if n=1
{decision edge label={left}{east}{#1}}
{decision edge label={right}{west}{#1}}
},
game tree/.style={
for tree={
s sep=30mm,l=25mm,
if n children=0{anchors=north}{
if n=1{anchors=south east}{anchors=south west}},
math content,
},
anchors=south,
dot={fill=white},for descendants={dot={fill=blue}},
delay={for descendants={split option={content}{;}{decision,content}}},
},
}
\newcommand\payoff[1]{\begin{matrix}#1\end{matrix}}
\begin{document}
\begin{figure}
\centering
\begin{forest}
game tree,
[
[$n_c$ buy;\payoff{\pi_1=\text{equation 1} \\ u_1=\text{utility 1}}]
[not buy;
[$1-n_c$ buy;\payoff{\pi_2=\text{equation 2} \\ u_2=\text{utility 2}},dot={fill=white}]
[not buy;\payoff{0 \\ 0},dot={fill=white}]
]
]
\draw[<-,shorten <=3pt]
(!r.anchor) -- + (2,1) node[right,align=left] {Entrepreneur\\
sets $P_c$ };
\draw[<-,shorten <=3pt]
(!2.anchor) -- + (2,1) node[right,align=left] {Entrepreneur\\
sets $P_r$ };
\draw[dotted](current bounding box.west|-!r.anchor)--(current bounding box.east|-!r.anchor)node[right,overlay]{$t=0$};
\draw[dotted](current bounding box.west|-!2.anchor)--(current bounding box.east|-!2.anchor)node[right,overlay]{$t=1$};
\draw[dotted](current bounding box.west|-!21.anchor)--(current bounding box.east|-!22.anchor)node[right,overlay]{$t=2$};
\end{forest}
\caption{Timing of game}
\label{Testing label}
% \floatfoot{\textit{Source}: Own illustration}
\end{figure}
\end{document}
Output
A shorter but inflexible forest
implementation:
Code
\documentclass[tikz]{standalone}
\usepackage{forest}\usetikzlibrary{arrows.meta}
\begin{document}
\begin{forest}
Pin/.style={pin={[pin edge={thin,shorten <=4\pgflinewidth,black,{Latex[round]}-,
to path={-- (\tikztotarget.west)}}, pin distance=1.5cm, align=left]
10:Entrepreneur\\ sets $P_#1$}},
buy/.style={edge label={node[inner sep=.1667em, /forest/if level=2{near end}{midway},
/forest/if n=1{above left}{above right}] {#1 buy}}},
c/.style={node options={circle,fill,outer sep=0pt,inner sep=.4mm},anchor=center},
foo/.style={anchor=parent, child anchor=parent, node options={align=left,
append after command={(.parent) edge[fill,to path={circle[radius=.4mm]}] ()}},
content={$\pi_{\pgfmathprint{level}} = {}$equation \pgfmathprint{level}\\
$u_{\pgfmathprint{level}} = {}$utility \pgfmathprint{level}}},
for tree={l sep=2.5cm, s sep*=5,if n=1{alias/.wrap pgfmath arg={level-#1}{level()}}{}}
[, c, Pin=c, alias=level-0
[, foo, buy=$n_c$]
[, c, buy=not, Pin=r
[, foo, buy=$1-n_c$]
[, foo, content={0\\0}, buy=not] ] ]
\path(current bounding box.west)coordinate(cbbw)(current bounding box.east)coordinate(cbbe);
\foreach \l[evaluate={\a={\l==0?"center":"north"};}] in {0,...,2}
\draw[dashed] (cbbw |- level-\l.\a) -- (cbbe |- level-\l.\a) node[right] {$t=\l$};
\end{forest}
\end{document}