这些树出现在现代概率论中的分支链理论中。但我不知道如何通过 latex 实现它。有人能帮忙吗?
以下是我的要求:
- 树木需要水平生长;
- 边缘可以有不同的长度,可以自行调整;
- 每个边缘末端都有一个空心圆圈;
- 一棵树有斜边,另一棵树有方形边缘。
提前致谢...
编辑:感谢@Jasper Habicht 的评论。以下是我尝试的:
\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
edge path={
\noexpand\path[\forestoption{edge}] (!u.parent anchor) -- +(0.2cm,0) |- (.child anchor)\forestoption{edge label};},
grow=0,
reversed,
parent anchor=east,
child anchor=west,
anchor=west
}
[, l = 2cm
[, l = 1cm]
[, l = 2cm
[ , l = 2cm]
[ , l = 1cm]
]
]
\end{forest}
\end{document}
我期望得到一棵像上图第二棵那样的水平树,但它失败了,结果变成了一棵奇怪的单线树……我不明白为什么。而且我无法使边以坚果结尾……
任何评论和提示都将受到赞赏...TIA。
答案1
就像这样(但可能存在更优雅的方式来做到这一点):
\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
circle,
draw,
inner sep=1pt,
edge path={
\noexpand\path[\forestoption{edge}] (!u.parent anchor)
|- (.child anchor)\forestoption{edge label};
},
where level={0}{
draw=none,
parent anchor=east,
}{},
grow=0,
reversed,
s sep=0.5cm,
length/.style={
before computing xy={l=#1},
}
}
[{}
[{}, length=0.5cm
[{}, length=1.5cm]
[{}
[{}, length=3cm]
[{}, length=2cm]
]
]
]
\end{forest}
% same code as above, the only difference is -- instead of |- in edge path option:
\begin{forest}
for tree={
circle,
draw,
inner sep=1pt,
edge path={
\noexpand\path[\forestoption{edge}] (!u.parent anchor)
-- (.child anchor)\forestoption{edge label};
},
where level={0}{
draw=none,
parent anchor=east,
}{},
grow=0,
reversed,
s sep=0.5cm,
length/.style={
before computing xy={l=#1},
}
}
[{}
[{}, length=0.5cm
[{}, length=1.5cm]
[{}
[{}, length=3cm]
[{}, length=2cm]
]
]
]
\end{forest}
\end{document}