# How draw this game in Tikz?

I want to draw the two following picture in Tikz and insert in my LaTeX document, any ready code would be appreciated.

Please note that the context of these pictures are game theory and extensive form games.

Here's a straightforward recreation of the first:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[>=Stealth]
\coordinate (x5) at (-3, 2);
\coordinate (x1) at ( 0, 2);
\coordinate (x3) at ( 3, 2);
\coordinate (x6) at (-3, -2);
\coordinate (x2) at ( 0, -2);
\coordinate (x4) at ( 3, -2);
\coordinate (r1) at (-5, 3);
\coordinate (r2) at (-5, 1);
\coordinate (r3) at (-5, -1);
\coordinate (r4) at (-5, -3);
\coordinate (r5) at ( 5, 3);
\coordinate (r6) at ( 5, 1);
\coordinate (r7) at ( 5, -1);
\coordinate (r8) at ( 5, -3);
\coordinate (o) at (-1.25, 0);
\node[circle, draw, inner sep=0.15em] (oc) at (o) {};
\node[anchor=north west] at (x1) {$x_1$};
\node[anchor=north west] at (x5) {$x_5$};
\node[anchor=north east] at (x3) {$x_3$};
\node[anchor=south west] at (x2) {$x_2$};
\node[anchor=south west] at (x6) {$x_6$};
\node[anchor=south east] at (x4) {$x_4$};
\node[anchor=east] at (r1) {3, 0};
\node[anchor=east] at (r2) {3, 2};
\node[anchor=east] at (r3) {0, 3};
\node[anchor=east] at (r4) {3, 2};
\node[anchor=west] at (r5) {2, 3};
\node[anchor=west] at (r6) {2, 2};
\node[anchor=west] at (r7) {2, 3};
\node[anchor=west] at (r8) {2, 2};
\node[anchor=north east] at (o) {Nature};
\draw[->] (oc.75) -- (x1) node[midway, anchor=east] {[.5]1};
\draw[->] (oc.285) -- (x2) node[midway, anchor=east] {[.5]2};
\draw[->] (x1) -- (x3) node[midway, anchor=south] {Average};
\draw[->] (x1) -- (x5) node[midway, anchor=south] {Hunk\vphantom{g}};
\draw[->] (x2) -- (x4) node[midway, anchor=north] {Average};
\draw[->] (x2) -- (x6) node[midway, anchor=north] {Hunk};
\draw[->] (x5) -- (r1) node[near end, anchor=south west] {Hunk};
\draw[->] (x5) -- (r2) node[near end, anchor=north west] {Average};
\draw[->] (x6) -- (r3) node[near end, anchor=south west] {Hunk};
\draw[->] (x6) -- (r4) node[near end, anchor=north west] {Average};
\draw[->] (x3) -- (r5) node[near end, anchor=south east] {Hunk};
\draw[->] (x3) -- (r6) node[near end, anchor=north east] {Average};
\draw[->] (x4) -- (r7) node[near end, anchor=south east] {Hunk};
\draw[->] (x4) -- (r8) node[near end, anchor=north east] {Average};
\draw[dashed] (x5) -- (x6) node[pos=0.45, anchor=east] {Tina} node[pos=0.45, anchor=west] {$h_{T2}$};
\draw[dashed] (x3) -- (x4) node[midway, anchor=west] {Tina} node[midway, anchor=east] {$h_{T1}$};
\draw[dashed] (x1) -- (x2) node[midway, anchor=west] {Gina} node[midway, anchor=east] {$h_G$};
\end{tikzpicture}
\end{document}


Some notes:

• You can tweak the coordinates to move the various nodes around --- I've named them according to their labels (r1 ... r8 are results, o is the origin, oc the origin circle).
• Edge labels are mostly positioned midway, but I've manually moved one using pos=... to make the whole thing look better (midway is equivalent to pos=0.5 FWIW).
• >=Stealth in changes the default arrow tips to the Stealth tips from the arrows.meta TikZ library (which must be loaded for this to work).
• I've used a \vphantom{g} in one of the edge labels to make sure the different depths of "Hunk" and "Average" do not lead to uneven placement of those labels.

EDIT: and of the second:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc}
\begin{document}
\begin{tikzpicture}[>=Stealth]
\coordinate (x5) at (-2,  2);
\coordinate (x1) at ( 0,  2);
\coordinate (x3) at ( 2,  2);
\coordinate (x6) at (-2, -2);
\coordinate (x2) at ( 0, -2);
\coordinate (x4) at ( 2, -2);
\coordinate (r1) at (-3,  3);
\coordinate (r2) at (-3,  1);
\coordinate (r3) at (-3, -1);
\coordinate (r4) at (-3, -3);
\coordinate (o)  at ( 0,  0);
\coordinate (rl) at (-2.5, -0.5);
\node[anchor=north west] at (x1) {$x_u$};
\node[anchor=south west] at (x2) {$x_d$};
\node[anchor=south, yshift=0.75em] at (x1) {2};
\node[anchor=north] at (x2) {2};
\node[anchor=west] at (x3) {1, 1};
\node[anchor=west] at (x4) {1, 1};
\node[anchor=east] at (r1) {1, 2};
\node[anchor=east] at (r2) {0, 0};
\node[anchor=east] at (r3) {2, 0};
\node[anchor=east] at (r4) {1, 0};
\node[anchor=west, xshift=0.75em] at (o) {Nature};
\draw[->] (o) -- (x1) node[midway, anchor=east] {[.5]} node[midway, anchor=west] {U};
\draw[->] (o) -- (x2) node[midway, anchor=east] {[.5]} node[midway, anchor=west] {D};
\draw (x1) -- (x3) node[midway, anchor=south] {R};
\draw (x1) -- (x5) node[midway, anchor=south] {L};
\draw (x2) -- (x4) node[midway, anchor=north] {r};
\draw (x2) -- (x6) node[midway, anchor=north] {l};
\draw (x5) -- (r1) node[near end, anchor=south west] {t};
\draw (x5) -- (r2) node[near end, anchor=north west] {b};
\draw (x6) -- (r3) node[near end, anchor=south west] {t};
\draw (x6) -- (r4) node[near end, anchor=north west] {b};
\draw[rounded corners=0.25em] ($(x6) - (0.25,0.75)$) rectangle ($(x5) + (0.25,0.75)$);
\end{tikzpicture}
\end{document}


This is based on the first, and is almost equally straightforward; the only difference is that the calc TikZ library is used for computing the coordinates of the rectangle (information set? I don't know too much about game theory) so that the rectangle will adapt automatically if the coordinates are changed. I've also used the occasional xshift= and yshift= to move labels around to match your picture more closely.

I hope that this can serve as a starting point for learning TikZ --- like LaTeX itself, it has a steep learning curve, but once you get the hang of it it's a very powerful tool.

• Great, what about the second picture? Apr 28, 2021 at 7:35
• And please let me know to decrease the radios of Nature circle. Apr 28, 2021 at 7:45
• @Lisbeth I've made an edit to the code to make the Nature circle smaller --- for some reason you need to use inner sep there (I'm sure the resident TikZ experts can explain why this is, or suggest a better solution).
– chsk
Apr 28, 2021 at 8:03
• @Lisbeth added some code for the second as well.
– chsk
Apr 28, 2021 at 8:29
• @chsk: In order to draw the circle for Nature, you used a node with an empty content. While there is nothing to display, the node is not really empty because of the default inner sep which allows to let some space around the content in a node. By decreasing this inner sep, you decrease the size of the circle. If you want to increase it, it's better to use minimum width and minimum height. What you did is correct. Apr 28, 2021 at 9:40

Another try using the istgame package:

The first picture:

\documentclass[tikz]{standalone}

\usepackage{istgame}

\begin{document}

\begin{istgame}
\setistNewNodeStyle{solid node}[null node]
\setistmathTF001
\setxtshowarrows[thick]
\xtShowArrows
\xtHideEndPoints
% game start
\setistgrowdirection'{east}
\xtdistance{10mm}{40mm}
\istroot(0)[chance node]<[xshift=2mm]200>{Nature}
\istb{[.5]1}[l]
\istb{[.5]2}[l]
\endist
% right part
\xtdistance{30mm}{20mm}
\istroot(Ra)(0-1)<-45>{$x_1$}
\istb{Average}[a] \endist
\istroot(Rb)(0-2)<45>{$x_2$}
\istb{Average}[b] \endist
\xtdistance{20mm}{20mm}
\istroot(T1a)(Ra-1)<-135>{$x_3$}
\istb{Hunk}[above,sloped]{2,3}
\istb{Average}[below,sloped]{2,2}
\endist
\istroot(T1b)(Rb-1)<135>{$x_4$}
\istb{Hunk}[above,sloped]{2,3}
\istb{Average}[below,sloped]{2,2}
\endist
\xtInfoset[dashed](0-1)(0-2){$h_G$}[l]
\xtInfosetOwner(0-1)(0-2){Gina}[r]
\xtInfoset[dashed](T1a)(T1b){$h_{T1}$}[l]
\xtInfosetOwner(T1a)(T1b){Tina}[r]
% left part
\setistgrowdirection{west}
\xtdistance{30mm}{20mm}
\istroot(La)(0-1) \istb{Hunk}[a] \endist
\istroot(Lb)(0-2) \istb{Hunk}[b] \endist
\xtdistance{20mm}{20mm}
\istroot(T2a)(La-1)<-45>{$x_5$}
\istb{Hunk}[above,sloped]{3,0}
\istb{Average}[below,sloped]{3,2}
\endist
\istroot(T2b)(Lb-1)<45>{$x_6$}
\istb{Hunk}[above,sloped]{0,3}
\istb{Average}[below,sloped]{3,2}
\endist
\xtInfoset[dashed](T2a)(T2b){$h_{T2}$}[r]
\xtInfosetOwner(T2a)(T2b){Tina}[l]
\end{istgame}

\end{document}


The second picture:

\documentclass[tikz]{standalone}

\usepackage{istgame}

\begin{document}

\begin{istgame}
\setistNewNodeStyle{solid node}[null node]
\setistmathTF001
\xtdistance{20mm}{20mm}
\setistgrowdirection{west}
\istroot(0)[chance node]<0>{Nature}
\istB<grow=90>[->]{[.5]}[l]{U}[r]
\istB<grow=-90>[->]{[.5]}[l]{D}[r]
\endist
\istroot(a)(0-1)<90>{2}
\istb<grow=180>{L}[a]
\istb<grow=0>{R}[a]{1,1}[r]
\endist
\istroot(b)(0-2)<-90>{2}
\istb<grow=180>{l}[b]
\istb<grow=0>{r}[b]{1,1}[r]
\endist
\istroot(T2a)(a-1)
\istb{t}[a]{1,2}
\istb{b}[b]{0,0}
\endist
\istroot(T2b)(b-1)
\istb{t}[a]{2,0}
\istb{b}[b]{1,0}
\endist
\xtInfosetO[rounded corners=5pt](T2a)(T2b){1}(2em)
\xtOwner(a){$x_u$}[br]
\xtOwner(b){$x_d$}[ar]
\end{istgame}

\end{document}

• I am always agree this package when I see it :-) +1. Aug 16, 2021 at 12:29