我如何将标签添加到替代路径 (y_1、y_2、a_1、a_2......exc),以及如何使用森林将第二个子项转换为平方,如图 1 所示?
这是我的代码:
\begin{forest}
[,circle, draw,grow=east
[,circle, draw,grow=east,[,grow=east][,circle, draw,grow=east[...,grow=east][$u(a_1;\theta_1)$,grow=east]]][,circle, draw,grow=east[,grow=east][,circle, draw,grow=east[$u(a_1;\theta_2)$,grow=east][$u(a_1;\theta_1)$,grow=east]]]
]
\end{forest}
答案1
假设您有一个原始前言,即forest
没有库等的加载。
\documentclass[border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{forest}
for tree={grow=east,l sep'+=2em,s sep'+=1em},% l sep controls the length of branches, s sep controls how much they're pushed apart
before typesetting nodes={
where={>O_=O_=!&{content}{}{n children}{0}}% if there's no content but there are children
{draw,
if level=1{regular polygon,regular polygon sides=4}{circle}
}{anchor=parent},% if there is content or there aren't children, align anchors towards parent
},
my label/.style={if={>O_={n}{1}}{edge label={node[below,midway,font=\scriptsize]{$#1$}}}{edge label={node[above,midway,font=\scriptsize]{$#1$}}}}% if it's the first child, put the label below; o'w put it above
[
[,my label=y_2[,my label=a_2][,my label=a_1[$\cdots$,my label=\theta_2][$u(a_1;\theta_1)$,my label=\theta_1]]]
[,my label=y_1[,my label=a_2][,my label=a_1[$u(a_1;\theta_2)$,my label=\theta_2][$u(a_1;\theta_1)$,my label=\theta_1]]]
]
\end{forest}
\end{document}