有人能帮我写一下这段代码吗?我试着写了。谢谢
\begin{forest}
el/.style={edge label={node[auto,pos=0.6]{$#1$}}},
el'/.style={edge label={node[auto,pos=0.6,swap]{$#1$}}},
for tree={math content,s sep+=4em,l sep+=1.5em,edge={semithick,-latex}}
[(a,b)
[{((D,L)},el'=(a,b)]
[(D,R),el= (a,b)
[{(4,4,1},el'=c]
[{(6,0,0)},el=d]
]
]
\end{forest}
答案1
您可以使用tikz-cd
而不是 来执行此操作forest
。
\documentclass{article}
\usepackage{tikz-cd}
\tikzcdset{arrow style=tikz, diagrams={>=latex}}
\begin{document}
\[\begin{tikzcd}[row sep=1cm, column sep=0cm]
& (5,5,2) & & (4,4,1)\\
& & \{a,b\}\arrow[ul,"{(U,L)}"]\arrow[ur,"{(U,R)}"']\arrow[dl,"{(D,L)}"']\arrow[dr,"{(D,R)}"]\\
& P\arrow[dl,"N"']\arrow[dr,"P"] & & (5,5,2)\\
(4,4,1) & & (6,0,0)
\end{tikzcd}\]
\end{document}
答案2
如果需要绘制许多游戏树,另一个选择是使用游戏包裹:
\documentclass{standalone}
\usepackage{istgame}
\begin{document}
\begin{istgame}[->,font=\scriptsize]
\tikzset{oval node/.style={ellipse node,draw=none}}
\xtdistance{20mm}{40mm}
\istrooto'[90](0){\{a,b\}}
\istb{(U,L)}[bl]{(5,5,2)}
\istb{(U,R)}[br]{(4,4,1)}
\endist
\istrooto(0){\{a,b\}}
\istb[->-=.92]{(D,L)}[al]
\istb{(D,R)}[ar]{(5,5,2)}
\endist
\istrooto(1)(0-1){P}
\istb{N}[al]{(4,4,1)}
\istb{P}[ar]{(6,0,0)}
\endist
\end{istgame}
\end{document}