## 编译环境 操作系统 * [x ] Windows 7/8/10 * [ ] macOS * [ ] Linux `若需勾选,请把[ ]改成[x]` Tex发行版 * [x] TexLive `年份` * [ ] MikTeX `版本号` * [ ] CTeX `若需勾选,请把[ ]改成[x]` ## 我的问题 ``` \documentclass{article} \usepackage{tikz} \usetikzlibrary{trees} \begin{document} \begin{tikzpicture}[level distance=2cm, level 1/.style={sibling distance=4cm,sibling angle=30}, level 2/.style={sibling distance=4cm,sibling angle=30}] \node {root} child { node[align=center] {A.M\\(523,2.9291,3.6)} %A的第一个孩子C child {node [align=center]{C.L\\(32,1.0412,1.8)} child {node[align=center]{D.M\\(32,0.3378,0.4)}} child {node[align=center]{B.M\\(137,0.7034,1)} child {node[align=center]{F.M\\(137,0.7034,0.4)}} } } %A的第二个孩子B child {node [align=center]{B.M\\(210,0.7790,1.4)} child {node[align=center] {E.M\\(120,0.3660,0.8)} child {node[align=center] {F.M\\(120,0.3660,0,4)} } } child {node[align=center] {D.M\\(90,0.4129,0.8)}} } %A的第三个孩子E child {node [align=center]{E.M\\(150,1.109,0.8)} child {node[align=center] {F.M\\(96,0.51,1)}} child {node[align=center] {D.M\\(54,0.5990,0,4)}} } } child {node[align=center] {C.L\\(59,1.3121,1.2)} child {node [align=center]{ B.M\\(27,0.8601,0.4)}} child {node[align=center]{E.M\\(32,0.452,0.8)}} }; \end{tikzpicture} \end{document} ```

2 回答2

4
以后注意使用代码块,这样的MWE是没法用的。 你的主要问题是各级节点的水平距离不合理,可慢慢调整到合适的大小: ```tex \begin{tikzpicture}[level distance=2cm, level 1/.style={sibling distance=8cm,sibling angle=40}, level 2/.style={sibling distance=7cm,sibling angle=40}, level 3/.style={sibling distance=4cm,sibling angle=40}, ] ```
1
也可以使用宏包`forest`,示例如下 ![](https://wenda.latexstudio.net/data/attach/210215/oi3TheN7.png) ```tex \documentclass[tikz, border=2mm]{standalone} \usepackage{forest} \begin{document} \begin{forest} [root, for tree={l=2cm}, circle, draw [{A.M\\(523, 2.9291, 3.6)}, s sep=1cm [{C.L\\(32,1.0412,1.8)}, for tree={draw, fill=teal, line width=1pt} [{D.M\\(32,0.3378,0.4)}] [{B.M\\(137,0.7034,1)} [{F.M\\(137,0.7034,0.4)}] ] ] [{B.M\\(210,0.7790,1.4)}, for tree={fill=red!20} [{E.M\\(120,0.3660,0.8)} [{F.M\\(120,0.3660,0,4)}] ] [{D.M\\(90,0.4129,0.8)}] ] [{E.M\\(150,1.109,0.8)} [{F.M\\(96,0.51,1)}] [{D.M\\(54,0.5990,0,4)} [{C.L\\(59,1.3121,1.2)}, for tree={orange} [{B.M\\(27,0.8601,0.4)}] [{E.M\\(32,0.452,0.8)}] ] ] ] ] ] \end{forest} \end{document} ```

你的回答

请登录后回答

你的回答将会帮助更多人,请务必认真回答问题。