5

I'd like to typset the tree on the left of the image. Unfortunately, TikZ seems way to complicated to me... I tried with this code, without success enter image description here

\documentclass{beamer}
\usepackage{tikz} % Game theory packages
\usetikzlibrary{calc}

% Node styles
\tikzset{
% Two node styles for game trees: solid and hollow
solid node/.style={circle,draw,inner sep=1.5,fill=black},
hollow node/.style={circle,draw,inner sep=1.5}
}

\begin{document}

\begin{frame}
    \begin{tikzpicture}[scale=0.7,font=\footnotesize]
        % Specify spacing for each level of the tree
            \tikzstyle{level 1}=[level distance=18mm,sibling distance=27mm]
            \tikzstyle{level 2}=[level distance=18mm,sibling distance=27mm]
        % The Tree
        \node(0)[hollow node,label=above:{$1$}]{}
            child{node(1)[solid node, label=above:{$2$}]{}
                child{node(0-1-1)[solid node, label=above:{$1$}]{} edge from parent node[left]{$E$}}
                child{node(0-1-2)[label=below:{$(3,1)$}]{} edge from parent node[right]{$F$}}                                   
                    child{node(0-1-1-1)[label=below:{$(1,2)$}]{} edge from parent node[right]{$G$}} % The error is here
                edge from parent node[left,xshift=-3]{$C$}          
        }
            child{node(2)[label=below:{$(0,3)$}]{} edge from parent node[right, xshift=3]{$D$}
            };

        \end{tikzpicture}
\end{frame}
\end{document}

I'd like also to ask you if something easier for game theory than Tikz exists for trees.

9

Note that there is a package, istgame, which specializes on game trees. For general trees, forest is a very powerful tool. It allows you to draw your tree very easily.

\documentclass{article}
\usepackage{forest}
\forestset{el/.style={edge label={node [pos=0.7,above,outer sep=3pt] {$#1$} }}}
\begin{document}
\begin{forest}
for tree={circle,fill,inner sep=1pt,calign=fixed edge angles}
[,label=above:1
 [,label=above left:2,el=A
  [,label=above left:1,el=C
   [,label=below:{0,2},el=E ]
   [,label=below:{2,0},el=F ]
  ]
  [,label=below:{1,1},el=D]
 ]
 [,label=below:{3,3},el=B]
]
\end{forest}
\end{document}

enter image description here

5

My plain TikZ code is a bit long but easy to read.

enter image description here

\documentclass{article}
%\documentclass{beamer}
\usepackage{tikz}
\begin{document}
%\begin{frame}  
\begin{center}
\begin{tikzpicture}[scale=1,
h/.style={circle,draw=magenta,thick,inner sep=1.5},
s/.style={h,fill=magenta}]
\path
(0,0)     node[h] (1)  {} node[above] {1}  
+(1,-1)   node[s] (2b) {} node[below] {3,3}
++(-1,-1) node[s] (2a) {} node[left]  {2}  
+(1,-1)   node[s] (3b) {} node[below] {1,1}
++(-1,-1) node[s] (3a) {} node[left]  {1}  
+(1,-1)   node[s] (4b) {} node[below] {0,2}
+(-1,-1)  node[s] (4a) {} node[below] {2,0};

\draw (1)
--(2a) node[pos=.4,left]{A}
--(3a) node[pos=.4,left]{C}
--(4a) node[pos=.4,left]{E}
(1)--(2b)  node[pos=.4,right]{B}
(2a)--(3b) node[pos=.4,right]{D}
(3a)--(4b) node[pos=.4,right]{F};

\newcommand{\putcolumn}[6]{%
\path #1 node{#2} 
++(-90:1)  node{#3} ++(-90:1) node{#4}
++(-90:1)  node{#5} ++(-90:1) node{#6};
}%
\begin{scope}[shift={(4,0)}]
\draw (0,0) grid (2,-4);
\putcolumn{(.5,.5)}{C}{2,0}{0,2}{3,3}{3,3}
\putcolumn{(1.5,.5)}{D}{1,1}{1,1}{3,3}{3,3}
\putcolumn{(-.5,.5)}{}{AE}{AF}{BE}{BF}
\end{scope}
\end{tikzpicture}
\end{center}
%\end{frame}    
\end{document}
  • it works well with article, but some errors appear with beamer. Did I miss something? – Black Mild Aug 22 at 1:12
  • 3
    It works with beamer if you add [fragile], i.e. use \begin{frame}[fragile]. (+1) – Schrödinger's cat Aug 22 at 2:26
4

I propose this short code with pstricks – more specifically pst-tree:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{pst-tree}
\usepackage{auto-pst-pdf}

\begin{document}

\begin{pspicture}
\psset{tnsep=1pt, labelsep=3pt}
\pstree[nodesep=0pt, levelsep=1.5cm, treesep=3cm]{\Tc{2pt}~[ tnpos=a, tnsep=-1pt]{1}} {
        \pstree{\Tdot\nbput{$ A $} \uput[ul](\pssucc){$ 2 $}} {%
                \pstree{\Tdot \nbput{$ C $} \uput[ul](\pssucc){{1}}}{%
                        \pstree{\Tdot \nbput{$ E $} \uput[ul](\pssucc){{2}}}{}%
                        \Tdot\naput{$F$}\uput[d](\pssucc){$0,2$}}%
        \Tdot_{$D$} \uput[d](\pssucc){$1,1$}}%
\Tdot_{$B$} \uput[d](\pssucc){$3,3$}}
    \end{pspicture}%

 \end{document}

enter image description here

1

How to use the istgame package:

(You only need to briefly read three pages (pp.6-8) of the manual to do this.)

enter image description here

\documentclass{standalone}

\usepackage{istgame}

\begin{document}

\begin{istgame}
\xtShowEndPoints
\xtdistance{10mm}{20mm}
\istroot(0)[initial node]{1}
  \istb{A}[al]       \istb{B}[ar]{3,3}  \endist
\istroot(1)(0-1)<135>{2}
  \istb{C}[al]       \istb{D}[ar]{1,1}  \endist
\istroot(2)(1-1)<135>{1}
  \istb{E}[al]{2,0}  \istb{F}[ar]{0,2}  \endist
\end{istgame}

\end{document}
0

My attempt with tikz-qtree, but I did not find out how to fix the angles:

\usepackage{tikz-qtree}

\tikzset{grow'=down}

\begin{document}
    \begin{standalone}
        \begin{tikzpicture}[level distance=30pt,
                            sibling distance=10pt,
                            every tree node/.style={draw,circle,inner sep=0pt,minimum size=3pt},
                            edge from parent path={(\tikzparentnode) -- (\tikzchildnode)},
                            ]
            \Tree   [. \node[label=above:1] {}; 
                        \edge node[auto=left,pos=.6] {$B$};
                            [. \node[fill=black,label=below:{3,3}] {}; ]
                        \edge node[auto=right,pos=.6] {$A$};
                            [.\node[fill=black,label=above left:2] {}; 
                                \edge node[auto=left,pos=.6] {$D$};
                                    [.\node[fill=black,label=below:{1,1}] {}; ]
                                \edge node[auto=right,pos=.6] {$C$};
                                [.\node[fill=black,label=above left:1] {}; 
                                \edge node[auto=left,pos=.6] {$F$};
                                    [.\node[fill=black,label=below:{2,2}] {}; ]
                                \edge node[auto=right,pos=.6] {$E$};
                                    [.\node[fill=black,label=above left:2] {}; ] 
                                ]
                            ]
                    ]     
        \end{tikzpicture}   
    \end{standalone}
\end{document}

enter image description here

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.