我是 LaTeX 和论坛的新手。
对于我的硕士论文,我需要一棵博弈树。我想用概率标记分支。在这个论坛上,我发现大多数人会在 tikz 环境中使用“来自父节点的边缘”。但是,对我来说,它不起作用。该命令将以下分支的原点移到了上面分支的中间。我想要一些像上图所示的内容,我现在得到的是下图。有人知道如何修复它吗?
这是我的代码:
\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
正如你所看到的关于分支上的标签的另一个答案,您必须edge from parent node
在子描述末尾发出该内容。在您的代码中,将带有标签的分支更改\alpha
为:
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$} }
我得到:
我想这就是你要找的。这里强烈建议使用一个能突出显示匹配括号的优秀编辑器 ;-)。
完整代码如下:
\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}
答案2
这是使用游戏包裹:
\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}