13

I'm trying to use my limited knowledge of LaTeX to create a payoff matrix by hand. Here's my first try:

\begin{tabular}{cc|c|c|}
              &                 & Player $Y$      & \\
              &                 & $A$               & $B$ \\
\hline
Player $X$  & $A$               & $(x,y)$           & $(x,y)$ \\
\hline          
              & $B$           & $(x,y)$         & $(x,y)$ \\
\hline
\end{tabular}

However, what I've written isn't great, because

  • The lines extend too far, instead of simply creating a box enclosing the payoffs
  • How to center "Player X" and "Player Y" over the box?
  • There's also a mysterious "missing $" error.

Are there any tips I'm missing that would fix these issues and make this into a great-looking payoff matrix? Thanks for your help!

3 Answers 3

22

Please post complete minimal examples rather than code fragments. They make it much easier to help.

Maybe something like this?

I don't know why you would want 'Player Y' centred over any box, so I've assumed you don't really mean it.

\documentclass{article}
\usepackage{multirow,array}
\begin{document}
  \begin{table}
    \setlength{\extrarowheight}{2pt}
    \begin{tabular}{cc|c|c|}
      & \multicolumn{1}{c}{} & \multicolumn{2}{c}{Player $Y$}\\
      & \multicolumn{1}{c}{} & \multicolumn{1}{c}{$A$}  & \multicolumn{1}{c}{$B$} \\\cline{3-4}
      \multirow{2}*{Player $X$}  & $A$ & $(x,y)$ & $(x,y)$ \\\cline{3-4}
      & $B$ & $(x,y)$ & $(x,y)$ \\\cline{3-4}
    \end{tabular}
  \end{table}
\end{document}

payoff

Or possibly

  \begin{table}
    \setlength{\extrarowheight}{2pt}
    \begin{tabular}{*{4}{c|}}
      \multicolumn{2}{c}{} & \multicolumn{2}{c}{Player $Y$}\\\cline{3-4}
      \multicolumn{1}{c}{} &  & $A$  & $B$ \\\cline{2-4}
      \multirow{2}*{Player $X$}  & $A$ & $(x,y)$ & $(x,y)$ \\\cline{2-4}
      & $B$ & $(x,y)$ & $(x,y)$ \\\cline{2-4}
    \end{tabular}
  \end{table}

alternative

2
  • Many thanks again for your help CFR. I tried to generalize your first example to the 3x3 case without much success. Could you take a look at this question? tex.stackexchange.com/questions/304011/… Apr 13, 2016 at 3:58
  • @cfr experts (you also expert, 158k) suggest not to use vertical line. In this case is it good practice?
    – alhelal
    Mar 31, 2019 at 17:11
5

Check out the sgame package, which nicely packages this all up for you: https://www.economics.utoronto.ca/osborne/latex/sgame.pdf

Your example game could be written as:

\begin{game}{2}{2}[Player~X][Player~Y]
& $A$ & $B$ \\
$A$ &(x,y) &(x,y)\\
$B$ &(x,y) &(x,y)
\end{game}
1
  • Yes, it does the job, but unfortunately it is incompatible with the array package, which can be a stopper.
    – egreg
    Oct 30, 2019 at 16:07
1

Here is a solution with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{cccc}[cell-space-limits=3pt]
     &     & \Block{1-2}{Player $Y$} \\
     &     & $A$     & $B$ \\
\Block{2-1}{Player $X$} 
     & $A$ & \Block[hvlines]{2-2}{}
           $(x,y)$ & $(x,y)$ \\
     & $B$ & $(x,y)$ & $(x,y)$ 
\end{NiceTabular}

\end{document}

Output of the above code

You must log in to answer this question.

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