Writing Game Theory in LATEX

Thiago Nascimento da Silva  ·  Australian National University  ·  Reference Guide

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).

preamble.tex
\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
PackagePurposeNotes
sgameStrategic-form (payoff matrix) environmentsProvides the game environment
tikzExtensive-form game trees and diagramsRequires trees and calc libraries
amsmathDisplay equations, aligned environmentsPart of the AMS bundle
amssymbMath symbols: $\mathbb{R}$, $\succsim$, etc.Part of the AMS bundle
subfigSide-by-side figures / matricesAlternative: 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):

$$\text{P}_1:\; u_1(D,C) = 3 > u_1(C,C) = 2 > u_1(D,D) = 1 > u_1(C,D) = 0$$ $$\text{P}_2:\; u_2(C,D) = 3 > u_2(C,C) = 2 > u_2(D,D) = 1 > u_2(D,C) = 0$$

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).

LaTeX  →  Preview
\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}
Prisoner's Dilemma
Player 2
CD
Player 1C2, 20, 3
D3, 01, 1

Side-by-side matrices (generalization)

Use \begin{minipage} inside a figure environment. A % immediately after \end{minipage} suppresses the inter-minipage space.

LaTeX  →  Preview
\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}
$P_2$
CD
$P_1$C2, 20, 3
D3, 01, 1
$P_2$
CD
$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$:

$$u_i(a^*) \geq u_i(a_i,\, a^*_{-i}) \quad \forall\, 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

LaTeX  →  Preview
\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)
Player 2
CD
Player 1C2, 20, 3
D3, 01, 1
NE = (D, D)

Method 2: Dot notation

Place a superscript dot over each best-response payoff using a custom preamble command.

LaTeX  →  Preview
% 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}
Player 2
CD
Player 1C2, 20, 3
D3, 01, 1
NE = (D, D)
Common mistake Do not confuse the Nash equilibrium strategy profile with the payoff vector. The NE is $(D,D)$, not $(1,1)$: $(D,D)$ names the actions chosen; $(1,1)$ are the resulting payoffs.

Other classic 2×2 games

LaTeX  →  Preview
% 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 or Stravinsky?
Player 2
BachStravinsky
Player 1Bach3, 20, 0
Stravinsky0, 02, 3
Chicken (Hawk-Dove)
$P_2$
SwerveStraight
$P_1$Swerve0, 0−1, 1
Straight1, −1−10, −10
Matching Pennies
Player 2
HeadsTails
Player 1Heads1, −1−1, 1
Tails−1, 11, −1

Larger matrices

Adjust the first two arguments of game for any size. A 3×3 and a 2×4 example:

LaTeX  →  Preview
% 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}
3×3 matrix
$P_2$
Coop.DefectNeither
$P_1$Coop.$R,R$$S,T$$T,S$
Defect$T,S$$P,P$$R,S$
Neither$T,S$$P,P$$S,S$
2×4 matrix
$P_2$
CUncond. DImitateOpposite
$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.

LaTeX  →  Preview
% 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}
Example 1
$P_2$
$(q)$ A$(1-q)$ B
$P_1$$(p)$ A$\alpha, \beta$$\gamma, \delta$
$(1-p)$ B$\zeta, \eta$$\theta, \iota$
Example 2
$P_2$
$(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

LaTeX  →  Preview
\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}
P₁ C D P₂ P₂ C 2,2 D 0,3 C 3,0 D 1,1

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).

LaTeX  →  Preview
% 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
P₁ C D P₂ P₂ C 2,2 D 0,3 C 3,0 D 1,1
Double lines mark the SPNE path: NE = (D, D)

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.

LaTeX  →  Preview
% 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)$);
A $(p)$ B $(p{-}1)$ Nature P₁ C (σ−1,γ−2) D P₂ E (0,0) F (−10,−10) C (ρ+1,τ+2) D P₂ E (0,0) F (10,10)

§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.

LaTeX  →  Preview
\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}
C C C C C C 1 1 1 2 2 2 D φ,χ D ψ,ω D Γ,Δ D Θ,Λ D Ξ,Π D Σ,Υ Φ,Ψ

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.

LaTeX  →  Preview
\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}
P₃ X Y
$P_3 = X$
$P_2$
XY
$P_1$X1,1,12,0,2
Y0,2,02,2,2
$P_3 = Y$
$P_2$
XY
$P_1$X3,1,32,2,2
Y1,1,11,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).

LaTeX  →  Preview
% 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};
Nature 0.4 0.6 Sender t₁ L R Sender t₂ L R Receiver [p] [1−p] Receiver [q] [1−q] u (1,1) d (2,0) u (0,0) d (0,1) d (0,0) u (2,2) d (1,1) u (1,0)

§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.

LaTeX  →  Preview
% 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{array}{r|cc|cc|c} V_1 & C & \text{nr} & C & \text{nr} & \cdots \\ \text{stick}\leftarrow V_2 & C & \text{r} & C & \text{nr} & (C-K)+\tfrac{\delta R}{1-\delta} \end{array}$$ $$\begin{array}{r|cc|cc|cc|c} V_1 & C & \text{nr} & D & \text{nr} & C & \text{nr} & \cdots \\ \text{OSD}\leftarrow V_2 & C & \text{nr} & D & \text{r} & C & \text{nr} & C+\delta(P-K)+\tfrac{\delta^2 R}{1-\delta} \end{array}$$
Sticking is optimal when: $$\delta \geq \frac{K}{K+R-P} \in (0,1)$$
Deriving the threshold — LaTeX
\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*}