我有一個類似的問題,正如這裡所問的:如何設定樹中單一邊的樣式(TikZ)?
我有一棵樹,用 tikz 建造的。我想將一些單邊設計為虛線,而不是實線。所以我做了上面線程中提到的事情,它確實起作用了,但奇怪的是,節點本身的邊緣後面跟著具有傳入點狀邊緣的節點也是點狀的。為什麼?
這是上面提到的線程的範例,更改為虛線邊緣:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture} [
level 1/.style={sibling distance = 2cm, level distance = 1cm},
level 2/.style={sibling distance = 1cm},
level 3/.style={sibling distance = 1cm},
every node/.style={circle, draw=black,thin, minimum size = 0.5cm},
emph/.style={edge from parent/.style={dashed,red,very thick,draw}},
norm/.style={edge from parent/.style={solid,black,thin,draw}}
]
\begin{scope}[xshift=6cm]
\node{}
child[emph] { node {}
child[norm] { node {} }
child[norm] { node {}
child[emph] { node {} }
child { node {} }
}
}
child { node {}
child { node {} }
child { node {} }
}
child { node {} }
;
\end{scope}
\end{tikzpicture}
\end{document}
答案1
您需要添加solid
到every nodes/.style
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture} [
level 1/.style={sibling distance = 2cm, level distance = 1cm},
level 2/.style={sibling distance = 1cm},
level 3/.style={sibling distance = 1cm},
every node/.style={circle,solid, draw=black,thin, minimum size = 0.5cm},
emph/.style={edge from parent/.style={dashed,red,very thick,draw}},
norm/.style={edge from parent/.style={solid,black,thin,draw}}
]
\begin{scope}[xshift=6cm]
\node{}
child[emph] { node {}
child[norm] { node {} }
child[norm] { node {}
child[emph] { node {} }
child { node {} }
}
}
child { node {}
child { node {} }
child { node {} }
}
child { node {} }
;
\end{scope}
\end{tikzpicture}
\end{document}