我有这个树形图,但我需要在每个节点中添加额外的信息(例如 7+2+3=12),所以我需要将节点放大,以便信息能够很好地容纳。我该如何在节点上写这种信息?我现在不需要它,但我想知道是否也可以将信息添加到边缘。提前谢谢您。
level/.style={sibling distance=30mm/#1},
edge from parent/.style={->,draw} % <----
]
\node [circle,draw] {A}
child {node [circle,draw] {B}
child {node [circle,draw] {F}}
}
child {node [circle,draw] {C}
child {node [circle,draw] {D}
child {node [circle,draw] {G}
child {node [circle,draw] {F}
child {node [circle,draw] {H}}
}
child {node [circle,draw] {H}}
}
}
child {node [circle,draw] {E}
child {node [circle,draw] {F}}
}
};
\end{tikzpicture}
答案1
假设您愿意在树设计中考虑以下更改:
- 而不是
tikz
使用树forest
- 用圆角矩形替换圆形
- 节点中的文本可以是多行
- 附加信息采用较小的字体大小并最终使用不同的颜色
可能的解决方案是:
\documentclass[border=3.141592]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\usepackage{makecell}
\newcommand\main{\large\color{black}}
\begin{document}
\begin{forest}
for tree = {
% nodes
draw, rounded corners=1ex, minimum width=5em,
font=\scriptsize\linespread{0.84}\selectfont,
text=gray,
text badly centered,
% tree
edge = {-Straight Barb},
anchor=north,
child anchor=north,
l sep=6mm,
where level=0{s sep=7mm}{s sep=5mm},
tier/.option = level,
}
[\makecell{\main A\\
some long initial\\
text, root node}
[\makecell{\main B\\
$7 + 2 + 3 = 12$}
[\main F]
]
[\makecell{\main C\\
huh!}
[\main D
[\main G
[\makecell{\main F\\
$1+2=3$}
[\makecell{\main H\\
end of\\ branch}]
]
[\makecell{\main H\\
end of\\ branch}]
]
]
[\makecell{\main E\\
$1+2=3$}
[\makecell{\main F\\
end}]
]
]
]
\end{forest}
\end{document}