我创建了一个二叉树。这是我的代码:
\begin{tikzpicture}[level/.style={sibling distance=80mm/#1}]
\node[circle,draw](z){$50$}
child {node [circle,draw] {$30$}
child {node [circle,draw] {$10$}
\cm
child {node [circle,draw] {$20$}}}
child {node [circle,draw] {$40$}}}
child {node [circle,draw] {$80$}
child {node [circle,draw] {$60$}
\cm
child{node [circle,draw] {$70$}}}
child {node [circle,draw] {$90$}
child{node [circle,draw] {$85$}}
child{node [circle,draw] {$95$}}}};
\end{tikzpicture}
我怎样才能在节点旁边添加小数字,就像这里一样?
谢谢。
答案1
\cm
我不知道代码中的 的定义,所以我删除了它。您可以使用label
在原始节点周围放置另一个节点。请参阅pgfmanual sec 17.10.2 The Label Option
。
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}[level/.style={sibling distance=80mm/#1}]
\node[circle,draw,label={[red]above:{1}}](z){$50$}
child {node [circle,draw,label={[green]above left:{5}}] {$30$}
child {node [circle,draw,label={[green]above left:{5}}] {$10$}
child {node [circle,draw,label={[green]above left:{5}}] {$20$}}}
child {node [circle,draw,label={[teal]right:{5}}] {$40$}}}
child {node [circle,draw,label={[orange]above right:{6}}] {$80$}
child {node [circle,draw,label={[green]above left:{5}}] {$60$}
child{node [circle,draw,label={[green]above left:{5}}] {$70$}}}
child {node [circle,draw,label={[draw,rotate=45,orange, anchor=west]above right:{test code}}] {$90$}
child{node [circle,draw,label={[green]above left:{5}}] {$85$}}
child{node [circle,draw,label={[green]right:{5}}] {$95$}}}};
\end{tikzpicture}
\end{document}