4

I am new to LaTeX and also the forum.

For my master's thesis I need a game tree. I want to label the branches with probabilites. On this forum, I found that most people would use "edge from parent node" within the tikz environment. However, for me it does not work. The command shifted the origin of the following branches to the middle of the branch above. I would like to have someting like shown in the top picture, what I am getting currently is the bottom picture. Does anyone know how to fix it?

enter image description here

This is my code:

\documentclass{article}   \usepackage[a4paper,top=2cm,bottom=2cm,left=2cm,right=2cm,marginparwidth=1.35cm]{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\tikzstyle{level 1}=[level distance=15mm,sibling distance=6cm]
\tikzstyle{level 2}=[level distance=15mm,sibling distance=60mm]
\tikzstyle{level 3}=[level distance=15mm,sibling distance=50mm]
\tikzstyle{level 4}=[level distance=15mm,sibling distance=40mm]
\tikzstyle{level 5}=[level distance=15mm,sibling distance=30mm]
\tikzstyle{level 6}=[level distance=15mm,sibling distance=20mm]

\node(0){Deviate or Collude}
     child{node{Deviate}
        child{node{$R_{dev}$ - EDC}
            child{node{$R_{comp}$*$\delta$}
                child{node{$R_{comp}$*$\delta^2$}
                    child{node{$R_{comp}$*$\delta^3$}
                        child{node{...}}
        }}}}}
     child{node{Collude}
        child{node{$R_{cartel}$ - EDC - F}edge from parent  node{$\alpha$}[left]
            child{node{$R_{comp}$*$\delta$}
                child{node{$R_{comp}$*$\delta^2$}
                    child{node{$R_{comp}$*$\delta^3$}
                        child{node{...}
        }}}}}
        child{node{$R_{cartel}$}    
            child{node{($R_{cartel}$-EDC-F)*$\delta$}
                child{node{$R_{comp}$*$\delta^2$}
                    child{node{$R_{comp}$*$\delta^3$}
                        child{node{...}}}}}
            child{node{$R_{cartel}$*$\delta$}
                child{node{($R_{cartel}$- EDC - F)*$\delta^2$}
                    child{node{$R_{comp}$*$\delta^3$}
                        child{node{...}
                        }}}
                child{node{$R_{cartel}$*$\delta^2$}
                    child{node{($R_{cartel}$- EDC - F)*$\delta^3$}
                        child{node{...}}}
                    child{node{$R_{cartel}$*$\delta^3$}
                        child{node{...}}
                        child{node{...}}}
        }}}
     };
\end{tikzpicture}
\end{document}
  • 1
    You should consider a specialist package for this: istgame or a specialised tree package: forest or tikz-qtree. It would make your life much easier :). By the by, \tikzstyle is deprecated. – cfr Jun 28 '18 at 21:13
3

As you can see in the other answer about labels on branches, you have to issue the edge from parent node thing at the end of the child description. Changing, in your code, the branch with the \alpha label into:

 child{node{Collude}
         child{node{$R_{cartel}$ - EDC - F} 
             child{node{$R_{comp}$*$\delta$}
                child{node{$R_{comp}$*$\delta^2$}
                    child{node{$R_{comp}$*$\delta^3$}
                        child{node{...}
        }}}} 
          edge from parent  node[left,above] {$\alpha$} }

I obtain:

enter image description here

which I suppose is what you are looking for. A nice editor highlighting matching braces is highly suggested here ;-).

The complete code is:

\documentclass{article}
\usepackage[a4paper, top=2cm,bottom=2cm,left=2cm,right=2cm,marginparwidth=1.35cm]{geometry}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\tikzstyle{level 1}=[level distance=15mm,sibling distance=6cm]
\tikzstyle{level 2}=[level distance=15mm,sibling distance=60mm]
\tikzstyle{level 3}=[level distance=15mm,sibling distance=50mm]
\tikzstyle{level 4}=[level distance=15mm,sibling distance=40mm]
\tikzstyle{level 5}=[level distance=15mm,sibling distance=30mm]
\tikzstyle{level 6}=[level distance=15mm,sibling distance=20mm]

\node(0){Deviate or Collude}
     child{node{Deviate}
        child{node{$R_{dev}$ - EDC}
            child{node{$R_{comp}$*$\delta$}
                child{node{$R_{comp}$*$\delta^2$}
                    child{node{$R_{comp}$*$\delta^3$}
                        child{node{...}}
        }}}}}
     child{node{Collude}
         child{node{$R_{cartel}$ - EDC - F}
             child{node{$R_{comp}$*$\delta$}
                child{node{$R_{comp}$*$\delta^2$}
                    child{node{$R_{comp}$*$\delta^3$}
                        child{node{...}
        }}}}
         % edge from parent must close de "child" stanza
         edge from parent  node[left,above] {$\alpha$} }
        child{node{$R_{cartel}$}
            child{node{($R_{cartel}$-EDC-F)*$\delta$}
                child{node{$R_{comp}$*$\delta^2$}
                    child{node{$R_{comp}$*$\delta^3$}
                        child{node{...}}}}}
            child{node{$R_{cartel}$*$\delta$}
                child{node{($R_{cartel}$- EDC - F)*$\delta^2$}
                    child{node{$R_{comp}$*$\delta^3$}
                        child{node{...}
                        }}}
                child{node{$R_{cartel}$*$\delta^2$}
                    child{node{($R_{cartel}$- EDC - F)*$\delta^3$}
                        child{node{...}}}
                    child{node{$R_{cartel}$*$\delta^3$}
                        child{node{...}}
                        child{node{...}}}
        }}}
     };
\end{tikzpicture}
\end{document}
  • 1
    @cfr, sure, done. – Rmano Jun 29 '18 at 8:29
3

Here is another solution to use the istgame package:

enter image description here

\documentclass{standalone}

\usepackage{istgame}

\begin{document}

\begin{istgame}[xscale=1.1,font=\footnotesize]
\def\Rcar{{R_{cartel}}}
\def\Rcom{{R_{comp}}}
% tree
\tikzset{oval node/.style={box node,draw=none}}
\xtdistance{15mm}{50mm}
\istrooto(0){Deviate or Collude} \istb \istb \endist
\istrooto(D)(0-1){Deviate} \istb \endist
\istrooto(Da)(D-1){$R_{dev}-\mbox{EDC}$} \istb \endist
\istrooto(Db)(Da-1){$\Rcom*\delta$} \istb \endist
\istrooto(Dc)(Db-1){$\Rcom*\delta^2$} \istb \endist
\istrooto(Dd)(Dc-1){$\Rcom*\delta^3$} \istb{}{\cdots} \endist

\xtdistance{15mm}{50mm}
\istrooto(C)(0-2){Collude} \istb{\alpha}[al] \istb{1-\alpha}[ar] \endist
\istrooto(Ca)(C-1){$\Rcar-\mbox{EDC}-\mbox{F}$} \istb \endist
\istrooto(Cb)(Ca-1){$\Rcom*\delta$} \istb \endist
\istrooto(Cc)(Cb-1){$\Rcom*\delta^2$} \istb \endist
\istrooto(Cd)(Cc-1){$\Rcom*\delta^3$} \istb{}{\cdots} \endist

\xtdistance{15mm}{50mm}
\istrooto(RC0)(C-2){$R_{cartel}$} \istb{\alpha}[al] 
  \istb{1-\alpha}[ar] \endist
\istrooto(RC0a)(RC0-1){$(\Rcar-\mbox{EDC}-\mbox{F})*\delta$} 
  \istb{}{\cdots} \endist
\istrooto(RC0b)(RC0a-1){$\Rcom*\delta^2$} 
  \istb \endist
\istrooto(RC0c)(RC0b-1){$\Rcom*\delta^3$} 
  \istb{}{\cdots} \endist

\xtdistance{15mm}{40mm}
\istrooto(RC1)(RC0-2){$\Rcar*\delta$} 
  \istb{\alpha}[al] \istb{1-\alpha}[ar] \endist
\istrooto(RC1a)(RC1-1){$(\Rcar-\mbox{EDC}-\mbox{F})*\delta^2$} 
  \istb{}{\cdots} \endist
\istrooto(RC1b)(RC1a-1){$\Rcom*\delta^3$} 
  \istb{}{\cdots} \endist

\xtdistance{15mm}{30mm}
\istrooto(RC2)(RC1-2){$\Rcar*\delta^2$} \istb{\alpha}[al] 
  \istb{1-\alpha}[ar] \endist
\istrooto(RC2a)(RC2-1){$(\Rcar-\mbox{EDC}-\mbox{F})*\delta^3$} 
  \istb{}{\cdots} \endist

\xtdistance{15mm}{20mm}
\istrooto(RC3)(RC2-2){$\Rcar*\delta^3$} 
  \istb{\alpha}[al]{\cdots} \istb{1-\alpha}[ar]{\cdots} \endist
\end{istgame}
\end{document}

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.