3

I am having trouble on editing my Latex code to produce a figure (game) using the Tikz package.

I am trying to produce a three players game combining an extensive form (for player 3) and two matrices for player 1 and player 2. Below, I am sending the figure I produced:

game

The tex code I wrote for producing this game is:

    \begin{figure}[!htbp]
\centering
\caption*{Three Players Game: Combining Extensive Form with Matrix Form}\label{hybrid}
\begin{tikzpicture}[scale=1,font=\footnotesize,edge from parent/.style={draw,thick}]
  % Two node styles: solid and hollow
    \tikzstyle{solid node}=[circle,draw,inner sep=1.2];
    \tikzstyle{hollow node}=[circle,draw, inner sep=1.2];
  % Specify spacing for each level of the tree
    \tikzstyle{level 1}=[level distance=15mm,sibling distance=50mm]
    \tikzstyle{level 2}=[level distance=15mm,sibling distance=25mm]
  % The Tree
  \node(0)[hollow node]{}
    child{node{}
    edge from parent node[above left]{X}
    }
    child{node{}
    edge from parent node[above right]{Y}
    };
  % movers
  \node[above,circle,inner sep=1,yshift=4]at(0){1};
  \node[below]at(0-1){
    \gamemathfalse
    \arrayrulewidth.75pt
    \begin{game}{2}{2}[$P_{1}$][$P_{2}$]
           & X   & Y\\
       X & $1, 1, 1$ & $2, 0, 2$\\
       Y & $0, 2, 0$ & $2, 2, 2$
       \end{game}
         };
         \node[below,xshift=-15]at(0-2){
           \gamemathfalse
           \arrayrulewidth.75pt
           \begin{game}{2}{2}[$P_{1}$][$P_{2}$]
                  & X   & Y\\
              X & $3, 1, 3$ & $2, 2, 2$\\
              Y & $1, 1, 1$ & $1, 3, 1$
           \end{game}
         };
       \end{tikzpicture}
       \end{figure}

There are several things I would like to fix in this figure:

  1. Instead of the number "1" above the first node, I would like to have "P3" (for Player 3). I tried several things to substitute 1 by P3 such as including "label=above:{P3}" within the code line: "\node(0)[hollow node]{}". But the number 1 is still there.

  2. I would like to align the left matrix according to the end of the extensive form tree (similar to the alignment of the right matrix).

  3. If possible, I would like to have P3 and the extensive form below the matrix. That is, instead of having first the extensive form and then having it connected to the matrices from top to bottom, I would like to have first the two matrices on the top, and below to it the extensive form (as in the edited figure below).

In sum, this is the Tikz/game/figure I am looking for:

game edited

Thanks in advance!

  • 1
    Welcome to TeX.SE. Please complete your code to a minimal working example (MWE) so it is compilable. \gamemathfalse and the game environment you are using are unknown to me. A guess about point 1: the \node below the line % movers seems to set the 1 above the root. – Mike Oct 23 '17 at 22:46
  • And you could try to add grow’=up to the root node. And then check all the aboves and belowss. – Mike Oct 23 '17 at 22:51
6

Here are a few examples of your tree in various directions, using the istgame package. You can use \setistgrowdirection or its swap version \setistgrowdirection' to change the tree growing direction.

(I drew the game tables using the tabu package, because (as mentioned in the manual) the sgame package is not compatible with the memoir class or any other packages that load array.sty.)

enter image description here

\documentclass{article}

\usepackage{istgame}
\usepackage{tabu,makecell,multirow}
\DeclareExpandableDocumentCommand\xcol{mO{c}m}{\multicolumn{#1}{#2}{$#3$}}

\def\gameX{%
  \mbox{%
  \begin{tabu}spread0pt{X[c1]X[$c1]*2{|X[$c2]}|}
  \xcol2{} & \xcol2{P_2} \\
  \xcol2{} & \xcol1{X} &\xcol1{Y} \\\tabucline{3-}
  \multirowcell{2}{$P_1$}
    &  X   & 1,1,1     & 2,0,2    \\\tabucline{3-}
    &  Y   & 0,2,0     & 2,2,2    \\\tabucline{3-}
  \end{tabu}%
  }
}

\def\gameY{%
  \mbox{%
  \begin{tabu}spread0pt{X[c1]X[$c1]*2{|X[$c2]}|}
  \xcol2{} & \xcol2{P_2} \\
  \xcol2{} & \xcol1{X} &\xcol1{Y} \\\tabucline{3-}
  \multirowcell{2}{$P_1$}
    &  X   & 3,1,3     & 2,2,2    \\\tabucline{3-}
    &  Y   & 1,1,1     & 1,3,1    \\\tabucline{3-}
  \end{tabu}%
  }
}
\pagestyle{empty}

\begin{document}

\begin{itemize}
\item a tree: downward

\begin{istgame}
\xtdistance{15mm}{50mm}
\istroot(0)[initial node]{$P_3$}
  \istb{X}[al]{\gameX}[below,xshift=-8mm]
  \istb{Y}[ar]{\gameY}[below,xshift=-8mm]
  \endist
\end{istgame}

\item a tree: upward

\begin{istgame}
\setistgrowdirection'{north}
\xtdistance{15mm}{50mm}
\istroot(0)[initial node]<-90>{$P_3$}
  \istb{X}[bl]{\gameX}
  \istb{Y}[br]{\gameY}
  \endist
\end{istgame}

\item a tree: toward the right

\begin{istgame}
\setistgrowdirection'{east}
\xtdistance{20mm}{15mm}
\istroot(0)[initial node]<180>{$P_3$}
  \istb{X}[al]{\gameX}[above right,yshift=-2mm]
  \istb{Y}[bl]{\gameY}
  \endist
\end{istgame}
\end{itemize}

\end{document}

Added: You can draw the strategic games as you like. For example, if you prefer using the tabular environment (to tabu), replace the \def\gameX and \def\gameY parts above by the following:

\def\gameX{%
  \mbox{%
  \begin{tabular}{cc|c|c|}
  \xcol2{} & \xcol2{P_2} \\
  \xcol2{} & \xcol1{X} &\xcol1{Y} \\\cline{3-4}
  \multirowcell{2}{$P_1$}
    &  X   & 1,1,1     & 2,0,2    \\\cline{3-4}
    &  Y   & 0,2,0     & 2,2,2    \\\cline{3-4}
  \end{tabular}%
  }
}

\def\gameY{%
  \mbox{%
  \begin{tabular}{cc|c|c|}
  \xcol2{} & \xcol2{P_2} \\
  \xcol2{} & \xcol1{X} &\xcol1{Y} \\\cline{3-4}
  \multirowcell{2}{$P_1$}
    &  X   & 3,1,3     & 2,2,2    \\\cline{3-4}
    &  Y   & 1,1,1     & 1,3,1    \\\cline{3-4}
  \end{tabular}%
  }
}
  • Nice ;). But please consider warning users that the tabu package is a known health hazard. It has bugs which the author refuses to fix until the new version is published. At that point, existing code will fail as the new version will not be backwards-compatible and will support no backwards-compatibility option. That is, tabu will change in ways which require existing code to be rewritten. – cfr Jan 21 '18 at 0:19
  • @cfr. About the tabu issue, I added tabular codes to my previous answer. – InSung Cho Jan 22 '18 at 11:17
4

Something like this?

\documentclass[tikz,border=2pt]{standalone}
\usepackage{tikz}
\usepackage{sgame}

\begin{document}
\begin{tikzpicture}
  \node(0)[circle,draw,inner sep=1.2,label=below:$P_3$]{}
    [grow'=north,sibling distance=5cm]
    child{}
    child{}
  ;
  \node[anchor=south]at(0-1){
    \begin{game}22[$P_1$][$P_2$]
       & X & Y \\
      X&1,1,1&1,1,1\\
      Y&1,1,1&1,1,1
    \end{game}
  };
  \node[anchor=south]at(0-2){
    \begin{game}22[$P_1$][$P_2$]
       & X & Y \\
      X&1,1,1&1,1,1\\
      Y&1,1,1&1,1,1
    \end{game}
  };
\end{tikzpicture}
\end{document}

enter image description here

  • Great! I just included edge from parent node[below left]{X} and edge from parent node[below right]{Y} within brackets in child{}, to have the strategies/actions X and Y for player 3 in the figure. Thanks a lot! – Thiago Oct 23 '17 at 23:25

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.