4

Based on strategy / payoff matrix I would like to add arrows to indicate equilibria; in such a way that this

enter image description here

becomes like this

enter image description here

Any suggestion would be greatly appreciated.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}

\matrix[matrix of math nodes,every odd row/.style={align=right},every even row/.style={align=left},every node/.style={text width=1.5cm},row sep=0.2cm,column sep=0.2cm] (m) {
    10&5\\
    10&25\\
    5&20\\
    25&20\\
};
\draw (m.north east) rectangle (m.south west);
\draw (m.north) -- (m.south);
\draw (m.east) -- (m.west);

\coordinate (a) at ($(m.north west)!0.25!(m.north east)$);
\coordinate (b) at ($(m.north west)!0.75!(m.north east)$);
\node[above=5pt of a,anchor=base] {Low Price};
\node[above=5pt of b,anchor=base] {High Price};

\coordinate (c) at ($(m.north west)!0.25!(m.south west)$);
\coordinate (d) at ($(m.north west)!0.75!(m.south west)$);
\node[left=2pt of c,text width=1cm]  {Low Price};
\node[left=2pt of d,text width=1cm]  {High Price};

\node[above=18pt of m.north] (firm b) {Firm B};
\node[left=1.6cm of m.west,rotate=90,align=center,anchor=center] {Firm A};

\node[above=5pt of firm b]  {Payoff Matrix};
\end{tikzpicture}

\end{document}
2

3 Answers 3

7

I cite my earlier post on TeXwelt answering the question Spieltheorie Auszahlungsmatrix mit Pfeilen zur Darstellung von Equilibria.

A quick solution with just the drawing commands referring to matrix elements:

\draw [-latex, blue, very thick]
    (m-1-2.center) edge (m-1-1)
    ($(m-2-1.south)+(-0.55,0)$) edge ($(m-4-1.north)+(-0.55,0)$)
    (m-3-1.east) edge (m-3-2.center)
    ($(m-4-2.north)+(-0.55,0)$) to ($(m-2-2.south)+(-0.55,0)$);
\end{tikzpicture}

You can tweak the calculation values. I needed calculating because of the varying alignment per row. I would have preferred twice as much columns but consistent alignment for easier reference.

The lines above give, with the original code:

Payoff matrix

1
  • Beautiful! Works like a charm after updating {tikz}. Oct 12, 2015 at 15:15
6

First, I'll show just the matrix part. Then see the end of the answer for the full solution.

Here is a plain tabular solution, with a little lapping and stacking. I introduce \LA, \RA, \DA, and \UA for the left, right, down, and up arrows; and \Under{<number>}{<arrow>} for placing an up/down arrow under a given number. Since the tabular is right aligned, left and right arrows are placed after a data entry to achieve proper alignment.

\documentclass{article}
\usepackage{graphicx}
\usepackage{stackengine}
\newcommand\Under[2]{\strut\smash{\stackunder{#1}{#2}}}
\setstackgap{L}{1.1\normalbaselineskip}
\setstackgap{S}{2pt}
\def\LA{\rlap{\scalebox{2.8}[1.5]{\kern2pt\raisebox{-.5pt}{$\leftarrow$}}}}
\def\RA{\rlap{\scalebox{2.8}[1.5]{\kern2pt\raisebox{-.5pt}{$\rightarrow$}}}}
\def\UA{\tclap{\scalebox{1.5}[2.8]{$\uparrow$}}}
\def\DA{\bclap{\scalebox{1.5}[2.8]{$\downarrow$}}}
\renewcommand\arraystretch{1.5}
\begin{document}
\begin{tabular}{|rr|rr|}
\hline
&10\LA&&5\\
\Under{10}{\DA}&&\Under{25}{\UA}&\\
\hline
&5\RA&&20\\
25&&20&\\
\hline
\end{tabular}
\end{document}

enter image description here

For the full solution,

\documentclass{article}
\usepackage{graphicx}
\usepackage{stackengine}
\newcommand\Under[2]{\strut%
  \setstackgap{L}{1.1\normalbaselineskip}%
  \setstackgap{S}{2pt}%
  \smash{\stackunder{#1}{#2}}%
}
\def\LA{\rlap{\scalebox{2.8}[1.5]{\kern2pt\raisebox{-.5pt}{$\leftarrow$}}}}
\def\RA{\rlap{\scalebox{2.8}[1.5]{\kern2pt\raisebox{-.5pt}{$\rightarrow$}}}}
\def\UA{\tclap{\scalebox{1.5}[2.8]{$\uparrow$}}}
\def\DA{\bclap{\scalebox{1.5}[2.8]{$\downarrow$}}}
\renewcommand\arraystretch{1.5}
\begin{document}
\raisebox{-15pt}{\rotatebox{90}{Firm A}}~~
{\small\stackanchor[14pt]{\Longstack{High Price}}{\Longstack{Low Price}}}
\stackon{%
\begin{tabular}{|rr|rr|}
\hline
&10\LA&&5\\
\Under{10}{\DA}&&\Under{25}{\UA}&\\
\hline
&5\RA&&20\\
25&&20&\\
\hline
\end{tabular}%
}{\stackon[12pt]{\stackon[8pt]{\small Low Price High Price}{Firm B}}{Payoff Matrix}}
\end{document}

enter image description here

3

A PSTricks solution:

\documentclass{article}

\usepackage{pstricks-add}

\newcommand*\stack[2]{\shortstack[l]{#1\strut\\ #2\strut}}

\begin{document}

\begin{pspicture}(0.18,0)(6,4.95)
  \psframe(2,0)(6,3)
  \psline(4,0)(4,3)
  \psline(2,1.5)(6,1.5)
  \uput[180](2,0.75){\stack{High}{Price}}
  \uput[180](2,2.25){\stack{Low}{Price}}
  \rput(1,1.1){\psrotate(0,0){90}{Firm~A}}
  \uput[90](3,3){Low Price}
  \uput[90](5,3){High Price}
  \rput(4,4.1){Firm~B}
  \rput(4,4.8){Payoff Matrix}
  \uput[45](2,0){$25$}
  \uput[225](4,1.5){$5$}
  \uput[45](2,1.5){$10$}
  \uput[225](4,3){$10$}
  \uput[45](4,1.5){$25$}
  \uput[225](6,3){$5$}
  \uput[45](4,0){$20$}
  \uput[225](6,1.5){$20$}
 \psset{arrows = ->, linecolor = blue!70}
  \psline(2.3,1.55)(2.3,0.4)
  \psline(4.3,0.4)(4.3,1.55)
  \psline(3.92,1.25)(5.5,1.25)
  \psline(3.92,2.75)(5.65,2.75)
\end{pspicture}

\end{document}

output

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .