在下面的树中,我想在叶子对之间绘制 \hdots,例如在 8-9、10-11、12-13、14-15 之间。我在 forrest 包的手册中没有找到任何内容。我需要类似于
\node at ($(9)!.5!(10)$) {\Huge $\hdots$};
但我不知道如何引用我的福雷斯特节点。
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{automata}
\usetikzlibrary{calc,arrows.meta,positioning}
\newcommand{\iddots}{\reflectbox{$\ddots$}}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{forest}
for tree={
% nodes circle, draw,
semithick,
minimum size=1.3em, inner sep=0pt,
math content,
% tree
l sep =12mm,
s sep = 6mm,
% draw=cyan!60,
/tikz/arr/.style = { -{Triangle[angle=45:2pt 3]}, shorten >=1pt},
% for the case when you like to have
% all edges to bottom nodes dashed;
% using this, remove next code line with edge = arr,
%if level = 1{edge=arr}{edge={arr, dashed}},
edge = arr,
},
%% edge labels
/tikz/ELS/.style = {% Edge Label Style
pos=0.5, node
font=\footnotesize, text=blue, anchor=#1},
EL/.style={if n=1{edge label={node[ELS=east]{$#1$}}}
{edge label={node[ELS=west]{$#1$}}}}
%%%% diagram body
[, phantom, s sep = 1cm
[1, label=$\tilde{S}^1$, tier=0
[2, EL=1-p
[4, EL=1-p
[8, edge=dashed]
[9, edge=dashed]
]
[5, EL=p
[10,edge=dashed]
[11, edge=dashed]
]
]
[3, EL=p
[6, EL=1-p
[12, edge=dashed]
[13, edge=dashed]
]
[7, EL=p
[14, edge=dashed]
[15, edge=dashed]
]
]
]
[{$t=0$}
[{$t=1$}
[{$t=2$}
[{$t=T$}, edge=dashed]
]
]
]
]
\end{forest}
\end{document}
答案1
只需添加,name=foo
到您的节点括号中即可。
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{automata}
\usetikzlibrary{calc,arrows.meta,positioning}
\newcommand{\iddots}{\reflectbox{$\ddots$}}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{forest}
for tree={
% nodes circle, draw,
semithick,
minimum size=1.3em, inner sep=0pt,
math content,
% tree
l sep =12mm,
s sep = 6mm,
% draw=cyan!60,
/tikz/arr/.style = { -{Triangle[angle=45:2pt 3]}, shorten >=1pt},
% for the case when you like to have
% all edges to bottom nodes dashed;
% using this, remove next code line with edge = arr,
%if level = 1{edge=arr}{edge={arr, dashed}},
edge = arr,
},
%% edge labels
/tikz/ELS/.style = {% Edge Label Style
pos=0.5, node
font=\footnotesize, text=blue, anchor=#1},
EL/.style={if n=1{edge label={node[ELS=east]{$#1$}}}
{edge label={node[ELS=west]{$#1$}}}}
%%%% diagram body
[, phantom, s sep = 1cm
[1, label=$\tilde{S}^1$, tier=0
[2, EL=1-p
[4, EL=1-p
[8, edge=dashed, name=B1]
[9, edge=dashed, name=B2]
]
[5, EL=p
[10,edge=dashed]
[11, edge=dashed]
]
]
[3, EL=p
[6, EL=1-p
[12, edge=dashed]
[13, edge=dashed]
]
[7, EL=p
[14, edge=dashed]
[15, edge=dashed]
]
]
]
[{$t=0$}
[{$t=1$}
[{$t=2$}
[{$t=T$}, edge=dashed]
]
]
]
]
\draw[dotted,red] (B1) -- (B2);
\end{forest}
\end{document}
如果你想\hdots
在节点之间,将draw
命令替换为\path (B1) -- (B2) node[midway]{\dots};