5

Been working on some economics lately, and was able to figure out how to put together some 2x2 payoff matrix's but not sure how to go about doing a 3x3. I would like to keep the same general idea if possible, i.e. the tikz picture.

Here is what I have used to generate a 2x2.

%third matrix
%learn how to do 3x3
\begin{center}
\begin{tikzpicture}
\matrix[matrix of math nodes,every odd row/.style={align=right},every evenrow/.style={align=left},every node/.style={text width=1.5cm},row sep=0.2cm,column sep=0.2cm] (m) {
2&\bf{3}\\
4&\bf{2}\\
-1&\bf{0}\\
\bf{6}&0\\
};
\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] {Left};
\node[above=5pt of b,anchor=base] {Right};

\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]  {Up};
\node[left=2pt of d,text width=1cm]  {Down};

\node[above=18pt of m.north] (firm b) {Column};
\node[left=1.6cm of m.west,align=center,anchor=center] {Row};

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

enter image description here

  • 1
    The question is....? – user11232 Feb 15 '15 at 7:56
  • 1
    @HarishKumar: I think the OP wants to know how to modify his code for a 3 by 3 matrix. – Shahab Feb 15 '15 at 9:33
  • @Shahab And how does a 3 x 3 matrix look like? I don't know game theory! – user11232 Feb 15 '15 at 9:35
  • @HarishKumar: Basically 9 boxes instead of 4. – Shahab Feb 15 '15 at 9:36
  • @Shahab hehe. I think I know that much ;-) – user11232 Feb 15 '15 at 9:44
5

Please have a look at Will two-letter font style commands (\bf , \it , …) ever be resurrected in LaTeX?

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix,calc,positioning}
\begin{document}    
\begin{tikzpicture}
\def\myrowhead{{"Left","Up","Front"}}
\def\mycolhead{{"Right","Down","Back"}}

\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\\4&2&-1\\-1&0&0\\0&0&0\\2&3&6\\4&2&-1\\};
\foreach\x[count=\xi from 2,evaluate={\xx=int(2*\x);\xxi=int(\xx+1)}] in {1,2}{
  \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}{
  \node[text depth=0.25ex,above=2mm] at ($(m.north west)!{(2*\x+1)/6}!(m.north east)$) 
     {\pgfmathparse{\myrowhead[\x]}\pgfmathresult};
  \node[left=2mm] at ($(m.north west)!{(2*\x+1)/6}!(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}

enter image description here

  • Don't you need .append style instead of .style to make keep the node entries math. The OP had some entries \bf, that ought to be \mathbf. – Andrew Swann Feb 15 '15 at 12:41
  • @AndrewSwann Oops. I didn't even pay attention. Fixed now via nodes. Thanks. I'll leave the node ornaments to OP though. – percusse Feb 15 '15 at 12:49
  • The \bf is entirely for me just highlighting the number for game purposes. – User011123521 Feb 15 '15 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.