我有以下 Ti钾Z 树:
\begin{tikzpicture}[grow=south, level 1/.style={sibling distance=50pt}, level 3/.style={sibling distance=25pt}, level distance=30pt, every node/.style={draw, circle, inner sep=0pt, minimum size=5pt}, inner/.style={fill=black}]
\node {}
child {node[inner] {}
child {node {}
child {node[inner] {}
child {node {}
child {node[inner] {}
child {node {}}
}
child {node[inner] {}
child{ node {}}
}
}
}
child {node[inner] {}
child {node {}}
}
}
}
child {node[inner] {}
child {node {}
child {node[inner] {}
child {node {}
child {node[inner] {}
child{ node {}}
}
}
}
child {node[inner] {}
child {node {}}
}
}
}
;
\end{tikzpicture}
由此得出下图:
如您所见,黑色顶点 ( [inner]
) 只有一个子节点。我需要的是这个唯一子节点的边是very thick
。有没有一种巧妙的方法可以做到这一点,也许在 内inner/.style={...}
?
答案1
我建议切换到森林。在那里你可以实施简单的规则,例如
where n children=1{<do something>}{<otherwise>}
然而,看着你的树,我觉得实际的规则是
if={isodd(level)}{fill,for descendants={edge={very thick}}}{for descendants={edge={thin}}}
无论如何,我添加了这两个选项。如果真正的规则与它们两个不同,请告诉我。
\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={grow=south,circle,draw,
where n children=1{fill,for descendants={edge={very thick}}}{for descendants={edge={thin}}},
}
[
[
[
[
[
[[]]
[[]]
]
]
[[]]
]
]
[
[
[[[[]]]]
[[]]
]
]
]
\end{forest}
\begin{forest}
for tree={grow=south,circle,draw,
if={isodd(level)}{fill,for descendants={edge={very thick}}}{for descendants={edge={thin}}}
}
[
[
[
[
[
[[]]
[[]]
]
]
[[]]
]
]
[
[
[[[[]]]]
[[]]
]
]
]
\end{forest}
\end{document}