4

I use this manual for help with the drawing of game trees using TikZ (http://www.sfu.ca/~haiyunc/notes/Game_Trees_with_TikZ.pdf).

However, I have a challenge I cannot seem to overcome. Some of my end-nodes require line breaks in the labels. In the concrete example below, in the end node on the left in the second branch (after "Not Resist"), I would like the equation after the two vertical lines (||) to be placed below the first equation. In other words split the line between the X and the U_S.

I have tried by specifying "align=centre" and using \\ but it did not work. Similarly, I tried specifying an equation environment within the label, but it did not work either.

Any help would be most appreciated.

An MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}

\tikzset{
    solid node/.style={circle,draw,inner sep=1.5,fill=black},
    hollow node/.style={circle,draw,inner sep=1.5}
}

\begin{tikzpicture}[scale=1.5,font=\footnotesize]
    \tikzstyle{level 1}=[level distance=15mm, sibling distance=20mm]
    \tikzstyle{level 2}=[level distance=15mm, sibling distance=20mm]
          \node(0)[solid node,label=above:{\textbf{Sender}}]{}
              child{node(1)[hollow node, label=below:{$U_S(SQ)$}]{}
              edge from parent node[left,xshift=-3,yshift=5]{\textit{Not Threaten}}
              }
              child{node(2)[solid node, label=above right:{\textbf{Target}}]{}
                  child{node[hollow node, label=below:{$U_S(TS)=X$ \\ $||U_T(TS)=Y$}]{} edge from parent node[left,xshift=-3,yshift=0]{\textit{Not Resist}}}
                  child{node[hollow node, label=below:{$TF$}]{} edge from parent node[right,xshift=3,yshift=0]{\textit{Resist}}}
                  edge from parent node[right,xshift=3,yshift=5]{\textit{Threaten}}
                  };
  \end{tikzpicture}

\end{document}

A game tree model

5 Answers 5

4

You may use \makecell:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{makecell}
\begin{document}

\tikzset{
    solid node/.style={circle,draw,inner sep=1.5,fill=black},
    hollow node/.style={circle,draw,inner sep=1.5}
}

\begin{tikzpicture}[scale=1.5,font=\footnotesize]
    \tikzstyle{level 1}=[level distance=15mm, sibling distance=20mm]
    \tikzstyle{level 2}=[level distance=15mm, sibling distance=20mm]
          \node(0)[solid node,label=above:{\textbf{Sender}}]{}
              child{node(1)[hollow node, label=below:{$U_S(SQ)$}]{}
              edge from parent node[left,xshift=-3,yshift=5]{\textit{Not Threaten}}
              }
              child{node(2)[solid node, label=above right:{\textbf{Target}}]{}
                  child{node[hollow node, label=below:{\makecell{$U_S(TS)=X$ \\ $||U_T(TS)=Y$}}]{} edge from parent node[left,xshift=-3,yshift=0]{\textit{Not Resist}}}
                  child{node[hollow node, label=below:{$TF$}]{} edge from parent node[right,xshift=3,yshift=0]{\textit{Resist}}}
                  edge from parent node[right,xshift=3,yshift=5]{\textit{Threaten}}
                  };
  \end{tikzpicture}

\end{document}

enter image description here

1
  • Thanks a lot. A simple and straightforward solution. :-) Jul 11, 2016 at 18:56
1

Stack it!

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{stackengine}
\usepackage{tikz}
\begin{document}

\tikzset{
    solid node/.style={circle,draw,inner sep=1.5,fill=black},
    hollow node/.style={circle,draw,inner sep=1.5}
}

\begin{tikzpicture}[scale=1.5,font=\footnotesize]
    \tikzstyle{level 1}=[level distance=15mm, sibling distance=20mm]
    \tikzstyle{level 2}=[level distance=15mm, sibling distance=20mm]
          \node(0)[solid node,label=above:{\textbf{Sender}}]{}
              child{node(1)[hollow node, label=below:{$U_S(SQ)$}]{}
              edge from parent node[left,xshift=-3,yshift=5]{\textit{Not Threaten}}
              }
              child{node(2)[solid node, label=above right:{\textbf{Target}}]{}
                  child{node[hollow node, label=below:{\stackunder{$U_S(TS)=X ||$}{%
                     $U_T(TS)=Y$}}]{} edge from parent node[left,xshift=-3,yshift=0]{\textit{Not Resist}}}
                  child{node[hollow node, label=below:{$TF$}]{} edge from parent node[right,xshift=3,yshift=0]{\textit{Resist}}}
                  edge from parent node[right,xshift=3,yshift=5]{\textit{Threaten}}
                  };
  \end{tikzpicture}

\end{document}

enter image description here

If you want it aligned, tabstack it (note: for some reason, the || needed additional grouping inside the \slignstackunder):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabstackengine}
\stackMath
\usepackage{tikz}
\begin{document}

\tikzset{
    solid node/.style={circle,draw,inner sep=1.5,fill=black},
    hollow node/.style={circle,draw,inner sep=1.5}
}

\begin{tikzpicture}[scale=1.5,font=\footnotesize]
    \tikzstyle{level 1}=[level distance=15mm, sibling distance=20mm]
    \tikzstyle{level 2}=[level distance=15mm, sibling distance=20mm]
          \node(0)[solid node,label=above:{\textbf{Sender}}]{}
              child{node(1)[hollow node, label=below:{$U_S(SQ)$}]{}
              edge from parent node[left,xshift=-3,yshift=5]{\textit{Not Threaten}}
              }
              child{node(2)[solid node, label=above right:{\textbf{Target}}]{}
                  child{node[hollow node, label=below:{\alignstackunder{U_S(TS)=&X {||}}{%
                     U_T(TS)=&Y}}]{} edge from parent node[left,xshift=-3,yshift=0]{\textit{Not Resist}}}
                  child{node[hollow node, label=below:{$TF$}]{} edge from parent node[right,xshift=3,yshift=0]{\textit{Resist}}}
                  edge from parent node[right,xshift=3,yshift=5]{\textit{Threaten}}
                  };
  \end{tikzpicture}

\end{document}

enter image description here

1

you only need add to label style align=center:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\tikzset{
    solid node/.style={circle,draw,inner sep=1.5,fill=black},
    hollow node/.style={circle,draw,inner sep=1.5},
    every label/.append style={align=center}% <--- added
}
\begin{document}

\begin{tikzpicture}[scale=1.5,font=\footnotesize]
    \tikzstyle{level 1}=[level distance=15mm, sibling distance=20mm]
    \tikzstyle{level 2}=[level distance=15mm, sibling distance=20mm]
          \node(0)[solid node,label=above:{\textbf{Sender}}]{}
              child{node(1)[hollow node, label=below:{$U_S(SQ)$}]{}
              edge from parent node[left,xshift=-3,yshift=5]{\textit{Not Threaten}}
              }
              child{node(2)[solid node, label=above right:{\textbf{Target}}]{}
                  child{node[hollow node, label=below:{$U_S(TS)=X$ \\ $||U_T(TS)=Y$}]{} edge from parent node[left,xshift=-3,yshift=0]{\textit{Not Resist}}}
                  child{node[hollow node, label=below:{$TF$}]{} edge from parent node[right,xshift=3,yshift=0]{\textit{Resist}}}
                  edge from parent node[right,xshift=3,yshift=5]{\textit{Threaten}}
                  };
  \end{tikzpicture}
\end{document}

enter image description here

1

Edit: istgame v2.0 (codes improved for tree parts)

With the istgame v2.0, you can easily control the input modes and fonts for important labels using a new macro \setistmathTF*.

enter image description here

\documentclass{standalone}

\usepackage{istgame}
\usepackage{makecell}

\begin{document}

\begin{istgame}[scale=1.5,font=\footnotesize]
\setistmathTF*001<textbf>
\xtShowEndPoints[oval node]
\setistSolidNodeStyle{4pt}
\xtdistance{15mm}{20mm}
\istroot(0){Sender}
  \istb{Not Threaten}[al]{U_S(SQ)}
  \istb*{Threaten}[ar]
  \endist
\istroot(1)(0-2)<45>{Target}
  \istb{Not\ Resist}[al]{\mbox{\makecell{$U_S(TS)=X$\\$\|U_T(TS)=Y$}}}
  \istb{Resist}[ar]{TF}
  \endist
\end{istgame}

\end{document}

Original answer (istgame v1.0)

This is an example that uses the istgame package to draw the game tree and the makecell pacakage for the line break.

\documentclass{standalone}

\usepackage{istgame}
\usepackage{makecell}

\begin{document}

\begin{istgame}[scale=1.5,font=\footnotesize]
\xtShowEndPoints[oval node]
\setistSolidNodeStyle{4pt}
\xtdistance{15mm}{20mm}
\istroot(0)
  \istb{Not\ Threaten}[al]{U_S(SQ)}
  \istb*{Threaten}[ar]
  \endist
\istroot(1)(0-2)
  \istb{Not\ Resist}[al]{\mbox{\makecell{$U_S(TS)=X$\\$\|U_T(TS)=Y$}}}
  \istb{Resist}[ar]{TF}
  \endist
\xtOwner(0){\textbf{Sender}}
\xtOwner(1){\textbf{Target}}[ar]
\end{istgame}

\end{document}
0

You can use amsmath and gathered; the reason for \! is explained elsewhere in the site.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}

\tikzset{
  solid node/.style={circle,draw,inner sep=1.5,fill=black},
  hollow node/.style={circle,draw,inner sep=1.5}
}

\begin{tikzpicture}[scale=1.5,font=\footnotesize]
\tikzset{
  level 1/.style={level distance=15mm, sibling distance=20mm},
  level 2/.style={level distance=15mm, sibling distance=20mm},
}
\node(0)[solid node,label=above:{\textbf{Sender}}]{}
  child{
    node(1)[hollow node, label=below:{$U_S(SQ)$}]{}
    edge from parent node[left,xshift=-3,yshift=5]{\textit{Not Threaten}}
  }
  child{
    node(2)[solid node, label=above right:{\textbf{Target}}]{}
    child{
      node[hollow node, label=below:{
        $\!\begin{gathered}U_S(TS)=X \\ ||U_T(TS)=Y\end{gathered}$}]{} 
      edge from parent node[left,xshift=-3,yshift=0]{\textit{Not Resist}}}
      child{
        node[hollow node, label=below:{$TF$}]{} 
        edge from parent node[right,xshift=3,yshift=0]{\textit{Resist}}}
        edge from parent node[right,xshift=3,yshift=5]{\textit{Threaten}}
  };
\end{tikzpicture}

\end{document}

Note that \tikzstyle is deprecated.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .