Could anyone please show me how to extend the 3*3 tikz image described here:
Generating a 3x3 payoff matrix (Game-Theory)
into a 4*4 image?
Could anyone please show me how to extend the 3*3 tikz image described here:
Generating a 3x3 payoff matrix (Game-Theory)
into a 4*4 image?
Add one more entry to \myrowhead and \mycolhead
Add one more number to each row in the matrix
Add two more rows to the matrix
Let the \foreach run to 3
\foreach.\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{matrix,calc,positioning}
\begin{document}
\begin{tikzpicture}
\def\myrowhead{{"Left","Up","Front","Somewhere"}}
\def\mycolhead{{"Right","Down","Back","Dunno"}}
\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\\4&2&-1&9\\-1&0&0&2\\0&0&0&3\\2&3&6&1\\4&2&-1&8\\4&2&-1&8\\4&2&-1&8\\};
\foreach\x[count=\xi from 2,evaluate={\xx=int(2*\x);\xxi=int(\xx+1)}] in {1,2,3}{
\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)/8}!(m.south west)$)
{\pgfmathparse{\mycolhead[\x]}\pgfmathresult};
}
\node[above=18pt of m.north] (firm b) {Column};
\node[left=1.6cm of m.west,align=center,anchor=center] {Row};
\end{tikzpicture}
\end{document}