Tikz Payoff Matrix
Just to show you don't need a TikZ matrix to draw your table, some nested tabular
s are enough.
For convenience, I used a macro for the couple of payoffs, as in marmot's answer.
\documentclass[12pt]{article}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcommand{\pft}[2]{\begin{tabular}{@{}C{1em}@{\hspace{1.5em}}C{1em}@{}} \rule{0pt}{3ex} & #1 \\[1ex] #2 & \\[1ex] \end{tabular}}
\newcommand{\myh}[2]{\multicolumn{1}{C{#1}}{#2}}
\begin{document}
\begin{center}
\begin{tabular}{c@{}C{1.5em}|*4{C{4em}}}
& \myh{1.5em}{} & \multicolumn{4}{c}{Player 1} \\[1ex]
& \myh{1.5em}{} & \myh{4em}{T} & \myh{4em}{F} & \myh{4em}{G} & \myh{4em}{T} \\[1ex]
Player 2 &
\multicolumn{5}{c}{%
\begin{tabular}{@{}C{1.5em}|*4{C{4em}|}@{}}
\cline{2-5}
A & \pft{2}{12} & \pft{3}{2} & \pft{6}{9} & \pft{5}{9} \\
\cline{2-5}
B & \pft{-1}{0} & \pft{0}{0} & \pft{0}{0} & \pft{2}{3} \\
\cline{2-5}
\end{tabular}}
\end{tabular}
\end{center}
\end{document}
If you like to have "Player 2" rotated, you can use \rotatebox
from graphicx
package with the option origin=c
for a correct alignment:
\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcommand{\pft}[2]{\begin{tabular}{@{}C{1em}@{\hspace{1.5em}}C{1em}@{}} \rule{0pt}{3ex} & #1 \\[1ex] #2 & \\[1ex] \end{tabular}}
\newcommand{\myh}[2]{\multicolumn{1}{C{#1}}{#2}}
\begin{document}
\begin{center}
\begin{tabular}{c@{}C{1.5em}|*4{C{4em}}}
& \myh{1.5em}{} & \multicolumn{4}{c}{Player 1} \\[1ex]
& \myh{1.5em}{} & \myh{4em}{T} & \myh{4em}{F} & \myh{4em}{G} & \myh{4em}{T} \\[1ex]
\rotatebox[origin=c]{90}{Player 2} &
\multicolumn{5}{c}{%
\begin{tabular}{@{}C{1.5em}|*4{C{4em}|}@{}}
\cline{2-5}
A & \pft{2}{12} & \pft{3}{2} & \pft{6}{9} & \pft{5}{9} \\
\cline{2-5}
B & \pft{-1}{0} & \pft{0}{0} & \pft{0}{0} & \pft{2}{3} \\
\cline{2-5}
\end{tabular}}
\end{tabular}
\end{center}
\end{document}
I have tried to keep the same code skeleton you provided. The only thing that I might have changed is the two empty entires in \def\mycolhead{{"A","B","",""}}
(but it gets the job done nicely :)).
Newer Answer:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\usepackage{natbib}
\begin{document}
\begin{center}\begin{tikzpicture}
\def\myrowhead{{"T","F","G","T"}}
\def\mycolhead{{"A","B","",""}}
\matrix[matrix of math nodes,
draw, every odd row/.style={align=right},
every evenrow/.style={align=left},
nodes={text width=1.5cm},
row sep=0.2cm,column sep=0.2cm]
(m) {
2&3&6&5\\
12&2&9&9\\
-1&0&0&2\\
0&0&0&3\\
};
% Horizontal line
\draw ({$(m-2-1)!0.5!(m-3-1)$}-|m.west) -- ({$(m-2-1)!0.5!(m-3-1)$}-|m.east);
% Vertical lines
\foreach\x[count=\xi from 2,evaluate={\xx=int(2*\x);\xxi=int(\xx+1)}] in {1,...,3}{
\draw ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.north) -- ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.south);
}
\foreach\x in{0,1,2,3}{
\node[text depth=0.25ex,above=2mm] at ($(m.north west)!{(2*\x+1)/8}!(m.north east)$)
{\pgfmathparse{\myrowhead[\x]}\pgfmathresult};
\node[left=2mm] at ($(m.north west)!{(2*\x+1)/4}!(m.south west)$)
{\pgfmathparse{\mycolhead[\x]}\pgfmathresult};
}
\node[above=18pt of m.north] (firm b) {Player 1};
\node[left=1.6cm of m.west,align=center,anchor=center] {Player 2};
\end{tikzpicture}
\end{center}
\end{document}
Previous Answer:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\usepackage{natbib}
\begin{document}
\begin{center}\begin{tikzpicture}
\def\myrowhead{{"T","F","G","T"}}
\def\mycolhead{{"A","B","",""}}
\matrix[matrix of math nodes,
draw, every odd row/.style={align=right},
every evenrow/.style={align=left},
nodes={text width=1.5cm},
row sep=0.2cm,column sep=0.2cm]
(m){
2&3&6&5\\
12&2&9&9\\
-1&0&0&2\\
0&0&0&3\\
};
\foreach\x[count=\xi from 2,evaluate={\xx=int(2*\x);\xxi=int(\xx+1)}] in {1}{
\draw ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.north) -- ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.south);
\draw ({$(m-\xx-1)!0.5!(m-\xxi-1)$}-|m.west) -- ({$(m-\xx-1)!0.5!(m-\xxi-1)$}-|m.east);
}
\foreach\x in{0,1,2,3}{
\node[text depth=0.25ex,above=2mm] at ($(m.north west)!{(2*\x+1)/8}!(m.north east)$)
{\pgfmathparse{\myrowhead[\x]}\pgfmathresult};
\node[left=2mm] at ($(m.north west)!{(2*\x+1)/4}!(m.south west)$)
{\pgfmathparse{\mycolhead[\x]}\pgfmathresult};
}
\node[above=18pt of m.north] (firm b) {Player 1};
\node[left=1.6cm of m.west,align=center,anchor=center] {Player 2};
\end{tikzpicture}
\end{center}
\end{document}
This answer comes with a style payoff matrix
which does all the work for you. All you need to do is to say
\matrix [payoff matrix]{& T & F & G & T\\
A & \pft{2}{12} & \pft{3}{2} & \pft{6}{9} & \pft{5}{9} \\
B & \pft{-1}{0} & \pft{0}{0} & \pft{0}{0} & \pft{2}{3} \\
};
where \pft
takes two arguments, the entry at the top right and bottom left of the cell. The names of the players are stored in pgf keys so that you can change them easily.
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix}
\tikzset{payoff matrix/.style={matrix of nodes,column sep=-\pgflinewidth,row sep=-\pgflinewidth,
nodes={/utils/exec=\ifnum\the\pgfmatrixcurrentrow>1
\ifnum\the\pgfmatrixcurrentcolumn>1
\tikzset{
text height=1.2em,text width=4em,draw}
\fi
\fi,
align=center,anchor=center},
column 1/.style={text width=1em},
row 1/.style={text depth=0.3em},
execute at end matrix={%
\path (\tikzmatrixname-2-2.west) -- (\tikzmatrixname-2-\the\pgfmatrixcurrentcolumn.east)
coordinate[midway] (aux)
node[anchor=south,draw=none] at (\tikzmatrixname.north-|aux){\pgfkeysvalueof{/tikz/payoff
matrix/player 1}};
\path (\tikzmatrixname-2-2.north) --
(\tikzmatrixname-\the\pgfmatrixcurrentrow-2.south)
coordinate[midway] (aux)
node[anchor=south,draw=none,rotate=90] at (aux-|\tikzmatrixname.west){\pgfkeysvalueof{/tikz/payoff
matrix/player 2}};}},
payoff matrix/.cd,player 1/.initial={Player 1},player 2/.initial={Player 2}}
\begin{document}
\begin{tikzpicture}
\newcommand{\pft}[2]{{\hfill$#1$ \\ $#2$\hfill\mbox{}}}
\matrix [payoff matrix]{& T & F & G & T\\
A & \pft{2}{12} & \pft{3}{2} & \pft{6}{9} & \pft{5}{9} \\
B & \pft{-1}{0} & \pft{0}{0} & \pft{0}{0} & \pft{2}{3} \\
};
\end{tikzpicture}
\end{document}
And here is why I do believe it makes sense to use TikZ here: it is straightforward to add some features (and also Player 2
is rotated and centered without pain). (Of course I agree that if you do not want to have the freedom of adding features, and do not want to rotate Player 2
, a plain tabular is fine.)
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix}
\tikzset{payoff matrix/.style={matrix of nodes,column sep=-\pgflinewidth,row sep=-\pgflinewidth,
nodes={/utils/exec=\ifnum\the\pgfmatrixcurrentrow>1
\ifnum\the\pgfmatrixcurrentcolumn>1
\tikzset{
text height=1.2em,text width=4em,draw,
path picture={\fill[blue!20] (path picture bounding box.north west) -|
(path picture bounding box.south east);
\fill[red!20] (path picture bounding box.north west) |-
(path picture bounding box.south east);}}
\fi
\fi,
align=center,anchor=center},
column 1/.style={text width=1em},
row 1/.style={text depth=0.3em},
execute at end matrix={%
\path (\tikzmatrixname-2-2.west) -- (\tikzmatrixname-2-\the\pgfmatrixcurrentcolumn.east)
coordinate[midway] (aux)
node[anchor=south,draw=none,path picture={}] at (\tikzmatrixname.north-|aux){\pgfkeysvalueof{/tikz/payoff
matrix/player 1}};
\path (\tikzmatrixname-2-2.north) --
(\tikzmatrixname-\the\pgfmatrixcurrentrow-2.south)
coordinate[midway] (aux)
node[anchor=south,draw=none,path picture={},rotate=90] at (aux-|\tikzmatrixname.west){\pgfkeysvalueof{/tikz/payoff
matrix/player 2}};}},
payoff matrix/.cd,player 1/.initial={Player 1},player 2/.initial={Player 2}}
\begin{document}
\begin{tikzpicture}
\newcommand{\pft}[2]{{\hfill$#1$ \\ $#2$\hfill\mbox{}}}
\matrix [payoff matrix]{& T & F & G & T\\
A & \pft{2}{12} & \pft{3}{2} & \pft{6}{9} & \pft{5}{9} \\
B & \pft{-1}{0} & \pft{0}{0} & \pft{0}{0} & \pft{2}{3} \\
};
\end{tikzpicture}
\end{document}