This guide shows how to typeset game-theoretic objects in LaTeX — from payoff matrices to
extensive-form trees — using the sgame and tikz packages.
The Prisoner's Dilemma serves as the running example throughout.
§1 Packages & Setup
Include the following in your document preamble. The two key packages for game theory are
sgame (for payoff matrices) and tikz with the trees library
(for extensive-form game trees).
\documentclass[12pt]{article} % Encoding & layout \usepackage[utf8]{inputenc} \usepackage[margin=1in]{geometry} % Math \usepackage{amsthm, amsmath, amsfonts, mathtools, amssymb} % Game theory \usepackage{sgame, tikz} % sgame: matrices; tikz: trees \usetikzlibrary{trees, calc} % calc needed for info sets % Optional \usepackage{subfig} % side-by-side figures \usepackage{hyperref} % cross-references & links
| Package | Purpose | Notes |
|---|---|---|
sgame | Strategic-form (payoff matrix) environments | Provides the game environment |
tikz | Extensive-form game trees and diagrams | Requires trees and calc libraries |
amsmath | Display equations, aligned environments | Part of the AMS bundle |
amssymb | Math symbols: $\mathbb{R}$, $\succsim$, etc. | Part of the AMS bundle |
subfig | Side-by-side figures / matrices | Alternative: subcaption |
§2 Normal-Form Games (Payoff Matrices)
The Prisoner's Dilemma (PD) illustrates why two rational players may fail to cooperate even when cooperation is mutually beneficial, yielding a sub-optimal outcome. Formalized by Albert Tucker, it is the canonical example in non-cooperative game theory.
A normal-form game specifies: (i) a finite set of players $N = \{1, 2\}$; (ii) for each $i \in N$ a set of actions $S_i = \{C, D\}$, where $C$ = Cooperate and $D$ = Defect; and (iii) for each $i$ a payoff function $u_i : S_1 \times S_2 \to \mathbb{R}$.
Payoff preferences for PD, from best to worst (first action = Player 1, second = Player 2):
2×2 matrix
Use the game environment from sgame. The first optional argument labels
the row player (P1), the second labels the column player (P2). Each cell contains payoffs
as (P1, P2).
\begin{table}[htbp] \centering \caption{Prisoner's Dilemma} \begin{game}{2}{2}[Player 1][Player 2] & C & D \\ C & $2, 2$ & $0, 3$ \\ D & $3, 0$ & $1, 1$ \end{game} \end{table}
| C | D | ||
|---|---|---|---|
| Player 1 | C | 2, 2 | 0, 3 |
| D | 3, 0 | 1, 1 | |
Side-by-side matrices (generalization)
Use \begin{minipage} inside a figure environment. A %
immediately after \end{minipage} suppresses the inter-minipage space.
\begin{figure}[htbp] \centering \caption{Generalization of PD} \begin{minipage}{.5\textwidth} \begin{game}{2}{2}[$P_1$][$P_2$] & Cooperate & Defect \\ C & $2,2$ & $0,3$ \\ D & $3,0$ & $1,1$ \end{game} \end{minipage}% \begin{minipage}{.5\textwidth} \begin{game}{2}{2}[$P_1$][$P_2$] & Cooperate & Defect \\ C & $R,R$ & $S,T$ \\ D & $T,S$ & $P,P$ \end{game} \end{minipage} \end{figure}
| C | D | ||
|---|---|---|---|
| $P_1$ | C | 2, 2 | 0, 3 |
| D | 3, 0 | 1, 1 | |
| C | D | ||
|---|---|---|---|
| $P_1$ | C | $R, R$ | $S, T$ |
| D | $T, S$ | $P, P$ | |
§3 Nash Equilibrium
An action profile $a^*$ is a Nash equilibrium if, for every player $i$ and every action $a_i \in A_i$:
where $A_i$ is the set of actions for player $i$ and $u_i$ is a payoff function representing player $i$'s preferences. Two common conventions for marking best responses:
Method 1: Underlining best responses
\begin{game}{2}{2}[Player 1][Player 2] & C & D \\ C & $2, 2$ & $0, \underline{3}$ \\ D & $\underline{3}, 0$ & $\underline{1}, \underline{1}$ \end{game} % NE = (D, D)
| C | D | ||
|---|---|---|---|
| Player 1 | C | 2, 2 | 0, 3 |
| D | 3, 0 | 1, 1 | |
Method 2: Dot notation
Place a superscript dot over each best-response payoff using a custom preamble command.
% Define in preamble: \newcommand{\BR}[1]{\dot{#1}} \begin{game}{2}{2}[Player 1][Player 2] & C & D \\ C & $2, 2$ & $0, \BR{3}$ \\ D & $\BR{3}, 0$ & $\BR{1}, \BR{1}$ \end{game}
| C | D | ||
|---|---|---|---|
| Player 1 | C | 2, 2 | 0, 3 |
| D | 3, 0 | 1, 1 | |
Other classic 2×2 games
% Bach or Stravinsky \begin{game}{2}{2}[Player 1][Player 2] & Bach & Stravinsky \\ Bach & $3, 2$ & $0, 0$ \\ Stravinsky & $0, 0$ & $2, 3$ \end{game} % Chicken / Hawk-Dove \begin{game}{2}{2}[$P_1$][$P_2$] & Swerve & Straight \\ Swerve & $0, 0$ & $-1, 1$ \\ Straight & $1, -1$ & $-10,-10$ \end{game} % Matching Pennies \begin{game}{2}{2}[Player 1][Player 2] & Heads & Tails \\ Heads & $1,-1$ & $-1,1$ \\ Tails & $-1,1$ & $1,-1$ \end{game}
| Bach | Stravinsky | ||
|---|---|---|---|
| Player 1 | Bach | 3, 2 | 0, 0 |
| Stravinsky | 0, 0 | 2, 3 | |
| Swerve | Straight | ||
|---|---|---|---|
| $P_1$ | Swerve | 0, 0 | −1, 1 |
| Straight | 1, −1 | −10, −10 | |
| Heads | Tails | ||
|---|---|---|---|
| Player 1 | Heads | 1, −1 | −1, 1 |
| Tails | −1, 1 | 1, −1 | |
Larger matrices
Adjust the first two arguments of game for any size. A 3×3 and a 2×4 example:
% 3×3 \begin{game}{3}{3}[$P_1$][$P_2$] & Cooperate & Defect & Neither \\ Cooperate & $R,R$ & $S,T$ & $T,S$ \\ Defect & $T,S$ & $P,P$ & $R,S$ \\ Neither & $T,S$ & $P,P$ & $S,S$ \end{game} % 2×4 \begin{game}{2}{4}[$P_1$][$P_2$] & C & Uncond. D & Imitate & Opposite \\ C & $R,R$ & $S,T$ & $R,R$ & $S,T$ \\ D & $T,S$ & $P,P$ & $P,P$ & $T,S$ \end{game}
| Coop. | Defect | Neither | ||
|---|---|---|---|---|
| $P_1$ | Coop. | $R,R$ | $S,T$ | $T,S$ |
| Defect | $T,S$ | $P,P$ | $R,S$ | |
| Neither | $T,S$ | $P,P$ | $S,S$ | |
| C | Uncond. D | Imitate | Opposite | ||
|---|---|---|---|---|---|
| $P_1$ | C | $R,R$ | $S,T$ | $R,R$ | $S,T$ |
| D | $T,S$ | $P,P$ | $P,P$ | $T,S$ | |
Mixed strategies
Annotate row and column headers with mixing probabilities directly in the action labels.
% Example 1: 2×2 \begin{game}{2}{2}[$P_1$][$P_2$] & $(q)$ A & $(1-q)$ B \\ $(p)$ A & $\alpha,\beta$ & $\gamma,\delta$ \\ $(1-p)$ B & $\zeta,\eta$ & $\theta,\iota$ \end{game} % Example 2: 3×2 (P1 has three actions) \begin{game}{3}{2}[$P_1$][$P_2$] & $(q)$ D & $(1-q)$ E \\ $(x)$ A & $\iota,\kappa$ & $o,\pi$ \\ $(y)$ B & $\lambda,\mu$ & $\rho,\sigma$ \\ $(1-x-y)$ C & $\nu,\xi$ & $\tau,\upsilon$ \end{game}
| $(q)$ A | $(1-q)$ B | ||
|---|---|---|---|
| $P_1$ | $(p)$ A | $\alpha, \beta$ | $\gamma, \delta$ |
| $(1-p)$ B | $\zeta, \eta$ | $\theta, \iota$ | |
| $(q)$ D | $(1-q)$ E | ||
|---|---|---|---|
| $P_1$ | $(x)$ A | $\iota, \kappa$ | $o, \pi$ |
| $(y)$ B | $\lambda, \mu$ | $\rho, \sigma$ | |
| $(1{-}x{-}y)$ C | $\nu, \xi$ | $\tau, \upsilon$ | |
§4 Extensive-Form Games (Game Trees)
Extensive-form games are drawn with tikz using the child syntax.
Filled (solid) circles are decision nodes; open (hollow) circles mark terminal nodes with payoffs.
Prisoner's Dilemma in extensive form
\begin{tikzpicture}[thin, level 1/.style={sibling distance=40mm}, level 2/.style={sibling distance=25mm}, every circle node/.style={ minimum size=1.5mm, inner sep=0mm}] \node[circle,draw,label=above:$P_1$] {} child { node [circle,fill,label=above:$P_2$] {} child { node {$2,2$} edge from parent node[left] {$C$}} child { node {$0,3$} edge from parent node[right] {$D$}} edge from parent node[left] {$C$}} child { node [circle,fill,label=above:$P_2$] {} child { node {$3,0$} edge from parent node[left] {$C$}} child { node {$1,1$} edge from parent node[right] {$D$}} edge from parent node[right] {$D$}}; \end{tikzpicture}
Subgame Perfect Nash Equilibrium (double lines)
Mark the equilibrium path by adding a double style to the relevant edges.
In the PD, both players' dominant strategy is D, so the equilibrium path is P1→D and P2→D,
yielding payoff (1,1).
% Define spne style in preamble or locally: \tikzset{ spne/.style={double, double distance=1.5pt} } % Apply [spne] to equilibrium edges only: \node[circle,draw,label=above:$P_1$] {} child { node [circle,fill,label=above:$P_2$] {} child { node {$2,2$} edge from parent node[left] {$C$}} % off-path child { node {$0,3$} edge from parent node[right] {$D$}} % off-path edge from parent node[left] {$C$}} % off-path child { node [circle,fill,label=above:$P_2$] {} child { node {$3,0$} edge from parent node[left] {$C$}} % off-path child { node {$1,1$} edge from parent [spne] node[right] {$D$}} % SPNE edge from parent [spne] node[right] {$D$}}; % SPNE
Information sets (imperfect information)
Draw information sets as dashed rectangles enclosing nodes that share the same information
set, using the calc library. In the example below, Nature moves first (hollow root);
the two resulting P1 nodes cannot be distinguished by P1, so they are enclosed in one dashed
rectangle labelled P1. A dotted red box optionally highlights a subgame.
% Node styles \tikzset{ solid node/.style={circle,draw,inner sep=1.5,fill=black}, hollow node/.style={circle,draw,inner sep=1.5} } \tikzstyle{level 1}=[level distance=15mm,sibling distance=40mm] \tikzstyle{level 2}=[level distance=15mm,sibling distance=22mm] \tikzstyle{level 3}=[level distance=15mm,sibling distance=15mm] \node(0)[hollow node,label=above:{Nature}]{} child{node(1)[solid node]{} child{node[label=below:{$(\sigma{-}1,\gamma{-}2)$}]{} edge from parent node[left]{$C$}} child{node(3)[solid node,label=right:{$P_2$}]{} child{node[label=below:{$(0,0)$}]{} edge from parent node[left]{$E$}} child{node[label=below:{$(-10,-10)$}]{} edge from parent node[right]{$F$}} edge from parent node[right]{$D$}} edge from parent node[right,xshift=3]{$(p)$} edge from parent node[left,xshift=-3]{$A$}} child{node(2)[solid node]{} child{node[label=below:{$(\rho{+}1,\tau{+}2)$}]{} edge from parent node[left]{$C$}} child{node(6)[solid node,label=right:{$P_2$}]{} child{node[label=below:{$(0,0)$}]{} edge from parent node[left]{$E$}} child{node[label=below:{$(10,10)$}]{} edge from parent node[right]{$F$}} edge from parent node[right]{$D$}} edge from parent node[left,xshift=-3]{$(p{-}1)$} edge from parent node[right,xshift=3]{$B$}}; % P1 information set (nodes 1 and 2 are indistinguishable) \draw[dashed,rounded corners=10] ($(1)+(-.2,.25)$) rectangle ($(2)+(.2,-.25)$); \node at ($(1)!.5!(2)$) {$P_1$}; % Optional: red dotted box highlighting a subgame \draw[dotted,thick,red,rounded corners=15] ($(7)+(-.4,1.75)$) rectangle ($(8)+(.4,-.5)$);
§5 Further Examples
Centipede game
Players alternately choose to Continue (C) along the chain or Drop (D), earning the terminal payoff. Use a horizontal chain of decision nodes with downward Drop branches.
\begin{tikzpicture}[ hollow/.style={circle,draw,inner sep=1.5}, solid/.style={circle,draw,inner sep=1.5,fill}] % Place nodes manually (horizontal chain) \node[hollow,label=above:{1}] (n1) at (0,0) {}; \node[solid, label=above:{2}] (n2) at (2,0) {}; \node[hollow,label=above:{1}] (n3) at (4,0) {}; % ... continue as needed % Chain edges (C) \draw (n1) -- node[above]{C} (n2); \draw (n2) -- node[above]{C} (n3); % Drop branches (D) \draw (n1) -- node[right]{D} +(0,-1.2) node[below]{$\phi,\chi$}; \draw (n2) -- node[right]{D} +(0,-1.2) node[below]{$\psi,\omega$}; \end{tikzpicture}
Three-player game (extensive + matrix)
P3 moves first at the root, choosing X or Y. The induced 2×2 subgame between P1 (rows) and P2
(columns) is then displayed as a payoff matrix beneath each branch. Payoffs are listed as $(P_1, P_2, P_3)$.
In LaTeX, draw the P3 tree with tikzpicture and place the two matrices below using minipage.
\begin{figure}[htbp] \centering \caption{Three Players Game} % Step 1: P3 decision node at root, branches X and Y \begin{tikzpicture}[ level 1/.style={sibling distance=60mm}, every circle node/.style={ minimum size=1.5mm, inner sep=0mm}] \node[circle,draw,label=above:$P_3$] (root) {} child { node[draw=none] {} edge from parent node[left]{$X$}} child { node[draw=none] {} edge from parent node[right]{$Y$}}; \end{tikzpicture} \vspace{6pt} % Step 2: two matrices side by side, one per P3 action \begin{minipage}{.48\textwidth} \centering \small $P_3 = X$ \begin{game}{2}{2}[$P_1$][$P_2$] & X & Y \\ X & $1, 1, 1$ & $2, 0, 2$ \\ Y & $0, 2, 0$ & $2, 2, 2$ \end{game} \end{minipage}% \begin{minipage}{.48\textwidth} \centering \small $P_3 = Y$ \begin{game}{2}{2}[$P_1$][$P_2$] & X & Y \\ X & $3, 1, 3$ & $2, 2, 2$ \\ Y & $1, 1, 1$ & $1, 3, 1$ \end{game} \end{minipage} \end{figure}
| X | Y | ||
|---|---|---|---|
| $P_1$ | X | 1,1,1 | 2,0,2 |
| Y | 0,2,0 | 2,2,2 | |
| X | Y | ||
|---|---|---|---|
| $P_1$ | X | 3,1,3 | 2,2,2 |
| Y | 1,1,1 | 1,3,1 | |
Signaling game
Nature (solid node at centre) selects the Sender's type: $t_1$ with probability 0.4 (upward branch) or $t_2$ with 0.6 (downward branch). Each Sender node (solid) then chooses message $L$ (left) or $R$ (right), leading to a Receiver node (solid). The Receiver cannot observe the type — only the message — so the two $L$-nodes form one information set and the two $R$-nodes another, each enclosed in a dashed rectangle labelled Receiver. Belief probabilities $[p]$ and $[q]$ sit inside the information sets. The Receiver then chooses $u$ or $d$, reaching a terminal hollow node with payoffs (Sender, Receiver).
% Node styles \tikzset{ solid node/.style={circle,draw,inner sep=1.5,fill=black}, hollow node/.style={circle,draw,inner sep=1.5} } % Level spacing \tikzstyle{level 1}=[level distance=12mm,sibling distance=25mm] \tikzstyle{level 2}=[level distance=15mm,sibling distance=15mm] \tikzstyle{level 3}=[level distance=17mm,sibling distance=10mm] % Nature at root; t1 grows upward, t2 downward \node(0)[solid node,label=right:{Nature}]{} child[grow=up]{ node[solid node,label=left:{Sender $t=t_1$}]{} child[grow=left]{ node(1)[solid node,label=below:{$[p]$}]{} child{node[hollow node,label=left:{$(1,1)$}]{} edge from parent node[above]{$u$}} child{node[hollow node,label=left:{$(2,0)$}]{} edge from parent node[below]{$d$}} edge from parent node[above]{$L$}} child[grow=right]{ node(3)[solid node,label=below:{$[q]$}]{} child{node[hollow node,label=right:{$(0,0)$}]{} edge from parent node[below]{$d$}} child{node[hollow node,label=right:{$(2,2)$}]{} edge from parent node[above]{$u$}} edge from parent node[above]{$R$}} edge from parent node[right]{$0.4$}} child[grow=down]{ node[solid node,label=left:{Sender $t=t_2$}]{} child[grow=left]{ node(2)[solid node,label=above:{$[1-p]$}]{} child{node[hollow node,label=left:{$(0,0)$}]{} edge from parent node[above]{$u$}} child{node[hollow node,label=left:{$(0,1)$}]{} edge from parent node[below]{$d$}} edge from parent node[above]{$L$}} child[grow=right]{ node(4)[solid node,label=above:{$[1-q]$}]{} child{node[hollow node,label=right:{$(1,1)$}]{} edge from parent node[below]{$d$}} child{node[hollow node,label=right:{$(1,0)$}]{} edge from parent node[above]{$u$}} edge from parent node[above]{$R$}} edge from parent node[right]{$0.6$}}; % Information sets: dashed rectangles linking (1)-(2) and (3)-(4) \draw[dashed,rounded corners=10] ($(1)+(-.45,.45)$) rectangle ($(2)+(.45,-.45)$); \node at ($(1)!.5!(2)$) {Receiver}; \draw[dashed,rounded corners=10] ($(3)+(-.45,.45)$) rectangle ($(4)+(.45,-.45)$); \node at ($(3)!.5!(4)$) {Receiver};
§6 One-Shot Deviation Principle
To typeset the OSD comparison table, use an array environment with vertical bar
column separators to distinguish history columns from the payoff expression.
% Sticking strategy \begin{equation*} \begin{array}{r|cc|cc|cc} V_1 & C & \text{nr} & C & \text{nr} & \dots & \\ \text{stick}\leftarrow V_2 & C & \text{r} & C & \text{nr} & \dots & (C-K)+\frac{\delta R}{1-\delta} \end{array} \end{equation*} % One-shot deviation \begin{equation*} \begin{array}{r|cc|cc|cc|cc} V_1 & C & \text{nr} & D & \text{nr} & C & \text{nr} & \dots & \\ \text{OSD}\leftarrow V_2 & C & \text{nr} & D & \text{r} & C & \text{nr} & \dots & C+\delta(P-K)+\frac{\delta^2 R}{1-\delta} \end{array} \end{equation*}
\begin{equation*} \begin{array}{l} (C - K) + \delta R \geq C + \delta(P - K) \\ \delta(K + R - P) \geq K \\ \boxed{\delta \geq \dfrac{K}{K + R - P}} \in (0,1) \end{array} \end{equation*}