答案1
欢迎!我也是 TeX 的新手,我一直在使用这个文档:https://www.sfu.ca/~haiyunc/notes/Game_Trees_with_TikZ.pdf帮助我为一个项目绘制一些游戏树。
我使用以下代码绘制了此图:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{amsmath}
\RequirePackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{3pt}%
\title{Stack OverFlow Game Tree Question}
\author{Cassie}
\date{October 2021}
\begin{document}
% 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{tikzpicture}[scale=7,font=\footnotesize]
% Specify spacing for each level of the tree
\tikzstyle{level 1}=[level distance=5mm,sibling distance=5mm]
\tikzstyle{level 2}=[level distance=5mm,sibling distance=5mm]
% The Tree
\node(0)[hollow node]{A}
child{node(1)[hollow node]{B}
edge from parent node[left]{}
}
child{node(2)[hollow node]{C}
edge from parent node[right]{}
}
child{node(3)[hollow node]{D}
edge from parent node[right]{}
}
child{node(4)[hollow node]{E}
edge from parent node[right]{}
};
% draw lines
\draw[solid](1)to(2);
\draw[solid,bend right](2)to(4);
\draw[solid,bend right](1)to(3);
\end{tikzpicture}
\end{document}
我希望这个帮助能祝你好运!
答案2
您可以使用forest
包(基于tikz
包)简单地绘制树。有了它,代码会短得多:
\documentclass[margin=3.141592]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree = {
% nodes
circle, draw, minimum size=1.2em, inner sep=2pt,
% tree styles
s sep=6mm,
l sep=9mm
}
[A
[B, name=b]
[C, name=c]
[D, name=d]
[E, name=e]
]
% lines between nodes in the same level
\draw (b) to [bend right] (d)
(c) to [bend right] (e);
\end{forest}
\end{document}
答案3
这不是博弈树,但你也可以使用istgame
包来绘制图形。
\documentclass[tikz]{standalone}
\usepackage{istgame}
\begin{document}
\begin{istgame}
\setistNewNodeStyle{ellipse node}[minimum size=2em]
\setxtinfosetstyle{thin,solid}
\setistmathTF*011<sffamily>
\istrooto(0){A}
\istb
\istbA(1.3)
\istbA(1.6)
\istb
\endist
\istrooto(1)(0-1){B} \endist
\istrooto(2)(0-2){C} \endist
\istrooto(3)(0-3){D} \endist
\istrooto(4)(0-4){E} \endist
\xtInfoset(1)(2)
\xtInfoset(2)(4)
\xtCInfoset(3)(1)<1.5>
\end{istgame}
\end{document}