我想改變樹的某些邊緣的樣式。我想要一條從樹根到一片葉子的紅色虛線路徑。但是如果我改變一些特定的邊緣,下面的所有邊緣也會改變。連標籤也變紅了,這是我不想要的。
這就是發生的事情:
但我想要這樣的東西:
有什麼建議麼?這不可能那麼難。但我花了一個多小時試圖找出答案。這是我的程式碼:
\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}