3

For a Game theory exercise I have been trying to recreate the following tree using the TiKz package. I don't know if this package is the right approach but here is the tree I am attempting to replicate: enter image description here

If someone could provide an example of the code needed to do this specific kind of tree it would be of great help, as I can copy it to multiple other examples I have to work.

I am particularly struggling with the labels in the branches, the dotted line and the horizontal line at the beginning. This is why I do not share any attempt of code as it is all looking off and it would be detrimental to the post.

In case my preamble is needed please find it below:

**EDIT: PREAMBLE CLEANED

\documentclass[12pt, a4 paper]{article}

\usepackage{multicol} %Needed for \PDgame
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb}
\usepackage{parskip}
\usepackage{graphicx}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{verbatim}
\usepackage{subcaption}
\usepackage{indentfirst}
\usepackage{tikz}

% Margins
\usepackage[inner=2.0cm,outer=2.0cm,top=2.5cm,bottom=2.5cm]{geometry}
% Colour table cells
\usepackage[table]{xcolor}


\setlength{\marginparwidth}{2cm}
\begin{document}
\end{document}
8
  • 1
    Yes, TikZ has many possibilities to create any type of trees. Mar 19, 2021 at 22:29
  • Thanks, I have a vague idea that this is the right package (raised the question in case someone in the community had a different idea of the package I should use). I edited my question for clarity. Thanks for your response. Mar 19, 2021 at 22:42
  • 1
    For example, you have \usepackage{graphicx} two times in your code --> you load the same package twice. Mar 20, 2021 at 19:12
  • 1
    Last try before I go offline: (1) You still have \usepackage{mathtools} twice. Please carefully read your own preamble :). (2) As I stated before, tabu should not be used in my opinion, please read github.com/tabu-issues-for-future-maintainer/tabu. (3) In general, a preamble should be as short as possible. Remove all the packages that are not needed in order to describe your problem, see tex.meta.stackexchange.com/questions/228. Mar 20, 2021 at 19:23
  • 1
    BTW, \usepackage{mathtools} also loads amsmath automatically. Mar 20, 2021 at 19:31

3 Answers 3

7

the requested probability tree

Answer adapted from this question. To connect nodes simply name them and then you can draw lines between them. This is how the dashed line is done. The top two lines are just hard coded. There's probably a way to do it more automatically but I don't know it.

\documentclass[border=25]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\tikzset{
    solid node/.style={circle,draw,inner sep=1.2,fill=black},
}

\begin{tikzpicture}[font=\footnotesize]
    \tikzset{
        level 1/.style={level distance=15mm,sibling distance=65mm},
        level 2/.style={level distance=15mm,sibling distance=30mm},
        level 3/.style={level distance=15mm,sibling distance=15mm},
        level 4/.style={level distance=15mm,sibling distance=10mm},
  }

    \node(top)[solid node,label=above left:{1},red]{}
        child{[red]node[solid node,label=above:{1}]{}
        child{[black]node[solid node,label=left:{2}]{}
        child{[red]node[solid node,label=below:{\((6, 0)\)}]{}edge from parent node[left]{\(\alpha_2\)}}
        child{[red]node[solid node,label=below:{\((3, 1)\)}]{}edge from parent node[right]{\(\beta_2\)}}
        edge from parent node[left]{\(A_1\)}
    }
        child{node[solid node,label=below:{\((4,1)\)}]{}  % This is the branch that ends early
        edge from parent node[right]{\(B_1\)}
    }
        edge from parent node[left,xshift=-10]{\(a_1\)}
    }
        child{node[solid node,label=above:{2}]{}
        child{[red]node(A2)[solid node]{}
        child{node[solid node,black,label=below:{\((3, 3)\)}]{}edge from parent node[left]{\(\alpha_1\)}}
        child{[black]node[solid node,label=below:{\((1,5)\)}]{}edge from parent node[right]{\(\beta_1\)}}
        edge from parent node[left]{\(A_2\)}
    }
        child{node(B2)[solid node]{}
        child{[red]node[solid node,label=below:{\((4, 2)\)}]{}edge from parent node[left]{\(\alpha_1\)}}
        child{node[solid node,label=below:{\((5,1)\)}]{}edge from parent node[right]{\(\beta_1\)}}
        edge from parent node[right]{\(B_2\)}
    }
        edge from parent node[right,xshift=10]{\(b_1\)}
    };
    \draw[dashed] (A2) -- (B2) node[midway, above] {1};
    \coordinate (right angle) at ($(top) + (0, 1.5)$);
    \draw[red] (top) -- (right angle) node[midway, right,black] {\(C\)};
    \node[solid node,red,label=above:{2}] at (right angle) {};
    \draw[red] (right angle) -- ($(right angle) + (1.5, 0)$) node[black, midway, above] {\(S\)} node[below,black] {\((1, 2)\)};
    
\end{tikzpicture}
\end{document}
3

You might also use forest.

\documentclass{article}
\usepackage[edges]{forest}
\newcommand{\ur}[2][red]{\textcolor{#1}{\underline{\textcolor{black}{#2}}}}
\begin{document}
\begin{forest}
er/.style={edge=red},r/.style={color=red},rer/.style={r,er},
el/.style={edge label={node[midway,auto,color=black]{\ensuremath{#1}}}},
el'/.style={edge label={node[midway,auto,color=black,swap]{\ensuremath{#1}}}},
for tree={l sep+=2em,s sep+=2em,
    if n children=0{math content}{circle,inner sep=1pt,fill},
    if level=3{tier=bottom}{}}
[,r,label={90:1},alias=r,
    tikz+={\path[draw=red] ()-- node[auto]{$S$} ++ (2,0) node[below]{$(1,\ur{2})$};}
 [,rer,el={C},label={135:1}
  [,er,el'={\alpha},label={90:1}
   [,el'={A_1},label={135:2}
    [{(6,0)},el'={\alpha_2}]
    [{(3,1)},el={\beta_2}]
   ]
   [{(4,\ur{1})},er,el={B_1}
   ]
  ]
  [,label={90:2},el={b_1}
   [,er,el'={A_2},tikz+={\path[draw,dotted] () -- (!s);}
    [{(3,3)},er,el'={\alpha_1}]
    [{(1,5)},el={\beta_1}]
   ]
   [,el={B_2}
    [{(4,2)},er,el'={\alpha_1}]
    [{(1,5)},el={\beta_1}]
   ]
  ]
 ] 
]
\end{forest}
\end{document}

enter image description here

2
  • It's a small thing but the edges in the left subtree are not at the same angle as in the right subtree.
    – graffe
    Mar 20, 2021 at 11:04
  • 2
    @Anush You can work e.g. with caling=fixed edge angles, and there are many more options. However, I consider it a virtue that forest allows you to draw trees also in the space saving mode.
    – user237902
    Mar 20, 2021 at 15:20
3

Using the istgame package, you can do this:

  1. Draw the game tree:

enter image description here

\documentclass[tikz]{standalone}
    
\usepackage{istgame}

\begin{document}

\begin{istgame}
\xtdistance{10mm}{20mm}
\istroot[-45](0){2}
  \istb{C}[r]                \istb{S}[a]{(1,2)}[b]     \endist
\xtdistance{15mm}{60mm}
\istroot(1)(0-1)<135>{1}
  \istb{a_1}[al]             \istb{b_1}[ar]            \endist
\xtdistance{15mm}{30mm}
\istroot(2)(1-1){1}
  \istb{A_1}[al]             \istb{B_1}[ar]{(4,1)}     \endist
\istroot(3)(1-2){2}
  \istb{A_2}[al]             \istb{B_2}[ar]            \endist
\xtdistance{15mm}{15mm}
\istroot(2a)(2-1)<135>{2}
  \istb{\alpha_2}[al]{(6,0)} \istb{\beta_2}[ar]{(3,1)} \endist
\istroot(3a)(3-1)
  \istb{\alpha_1}[al]{(3,3)} \istb{\beta_1}[ar]{(1,5)} \endist
\istroot(3b)(3-2)
  \istb{\alpha_1}[al]{(4,2)} \istb{\beta_1}[ar]{(5,1)} \endist
\xtInfoset(3a)(3b){1}
\end{istgame}

\end{document}
  1. Analyze the game:

enter image description here

\documentclass[tikz]{standalone}
    
\usepackage{istgame}

\begin{document}

\begin{istgame}
\tikzset{KK/.style={draw=red,very thick}}

\xtdistance{10mm}{20mm}
\istroot[-45](0){2}
  \istb[KK]{C}[r]
  \istb[KK]{S}[a]{(1,2)}[b]
  \endist
\xtdistance{15mm}{60mm}
\istroot(1)(0-1)<135>{1}
  \istb[KK]{a_1}[al]
  \istb    {b_1}[ar] 
  \endist
\xtdistance{15mm}{30mm}
\istroot(2)(1-1){1}
  \istb    {A_1}[al]
  \istb[KK]{B_1}[ar]{(4,1)}
  \endist
\istroot(3)(1-2){2}
  \istb[KK]{A_2}[al]
  \istb    {B_2}[ar]
  \endist
\xtdistance{15mm}{15mm}
\istroot(2a)(2-1)<135>{2}
  \istb    {\alpha_2}[al]{(6,0)}
  \istb[KK]{\beta_2}[ar]{(3,1)}
  \endist
\istroot(3a)(3-1)
  \istb[KK]{\alpha_1}[al]{(3,3)}
  \istb    {\beta_1}[ar]{(1,5)}
  \endist
\istroot(3b)(3-2)
  \istb[KK]{\alpha_1}[al]{(4,2)}
  \istb    {\beta_1}[ar]{(5,1)}
  \endist
\xtInfoset(3a)(3b){1}
\end{istgame}

\end{document}
5
  • 1
    You have created a beautiful package. I'm sorry that it is used very little. +1
    – Sebastiano
    Mar 20, 2021 at 20:58
  • 1
    @Sebastiano Glad you like it. You may also like this package: tzplot(ctan.org/pkg/tzplot).
    – InSung Cho
    Mar 22, 2021 at 12:00
  • I am a modest user. First, I saw the link with your new package. It seems to me that you have simplified the tikz code to make it more simple and intuitive. It kind of reminds me of PSTricks. :-))) Always a modest suggestion. istgame is a beautiful package that I have used little but it is interesting. In my opinion you should expand the documentation with examples even the simplest ones, make better understand the commands for those who like me know little English and then display more complex examples. My best best regards.
    – Sebastiano
    Mar 22, 2021 at 21:34
  • @Sebastiano That's what I intended: to use TikZ but with more PSTricks like input.
    – InSung Cho
    Mar 24, 2021 at 2:49
  • No no...You have misunderstanding me....:-((( you new package tzplot remember me...PSTricks. I appreciated both your ist-game and tzplot. My always best regards.
    – Sebastiano
    Mar 24, 2021 at 21:10

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.