1

I want to draw the two following picture in Tikz and insert in my LaTeX document, any ready code would be appreciatedenter image description here.enter image description here

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

5

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}

enter image description here

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}

enter image description here

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.

8
  • Great, what about the second picture? – Lisbeth Apr 28 at 7:35
  • And please let me know to decrease the radios of Nature circle. – Lisbeth Apr 28 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 at 8:03
  • @Lisbeth added some code for the second as well. – chsk Apr 28 at 8:29
  • 1
    @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. – SebGlav Apr 28 at 9:40

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.