我有一个类似的问题,如下所问:如何设置树中单个边的样式(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}