答案1
您可能使用了tikz-qtree
包...不幸的是,它的文档没有描述如何添加边缘标签。但通过在这个网站上搜索,您可以找到问题的答案在 tikz-qtree 边缘定位标签可以简单适用于您的情况:
\documentclass[border=3.141502]{standalone}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}[every tree node/.style={draw,circle},
level distance=1.25cm,sibling distance=1cm,
edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}
]
\Tree [.$n_{0}$
\edge node[left] {$A$};
[.$n_{1}$ ]
\edge node[right] {$B$};
[.$n_{2}$ ]
]
\end{tikzpicture}
\end{document}
但是,使用该
forest
包也有替代解决方案。使用它向边缘添加标签相对简单:
\documentclass[border=3.141502]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree = {
% nodes style
circle, draw, inner sep=2pt,
minimum size=1.2em,
math content,
% tree style
l sep = 9mm,
s sep = 12mm,
/tikz/ELS/.style = {% Edge Label Style
node font=\scriptsize, inner sep=1pt,
pos=0.6, anchor=south #1},
EL/.style={if n=1{edge label={node[ELS=east]{$#1$}}}
{edge label={node[ELS=west]{$#1$}}}}
}
[n_{0}
[n_{1}, EL=A]
[n_{2}, EL=B]
]
\end{forest}
\end{document}