我想改变树的某些边的样式。我想要一条从根到树的一片叶子的红色虚线路径。但是如果我改变某些特定的边,下面的所有边也会改变。甚至标签也变成红色,这不是我想要的。
因此发生了以下事情:
但我想要这样的东西:
有什么建议吗?这应该不难。但我花了一个多小时才找到答案。这是我的代码:
\documentclass[border=10pt,svgnames]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,automata,backgrounds}
\definecolor{light-gray}{gray}{0.6}
\begin{document}
\centering
\begin{tikzpicture}[level distance=1.5cm,
level 1/.style={sibling distance=3cm},
level 2/.style={sibling distance=1cm},
level 3/.style={sibling distance=1cm},
every node/.style={thin}]
\node {1}
child {node {00}
child {node {00}}
child {node {}}
child {node {10}}
child {node {}}
}
child {node {}}
child {node {10}
child {node {00} edge from parent[dashed, very thick, red]
child {node {00}}
child {node {01}}
child {node {10}}
child {node {11} edge from parent[dashed, very thick, red]}
}
child {node {}}
child {node {}}
child {node {11}}
}
child {node {}};
\end{tikzpicture}
\end{document}
答案1
您可以使用Forest
使用简单的语法包来定制树的每个边,只需插入这样的边选项
edge={dashed,red,thick}
完整代码
\documentclass[border=10pt,svgnames]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={delay={where content={}{content={\phantom{00}}}{}},s sep+=5mm,l+=5mm}
[1
[00
[00]
[]
[10]
[]
]
[]
[10,edge={dashed,red,thick}
[00,edge={dashed,red,thick}
[00]
[01]
[10]
[11,edge={dashed,red,thick}]
]
[]
[]
[11]
]
[\phantom{00}]
]
\end{forest}
\end{document}