tikz trees: How to not draw a single edge
Edit: After clarifying, what is the problem, I suggest to try the following:
\documentclass[border=3mm,tikz,preview]{standalone}
\begin{document}
\begin{tikzpicture}[every node/.style={circle,draw}]
\node (r) {$r$}
child { node (T1) {$T_1$} }
child {node {$\ldots$} edge from parent[draw=none]}
child { node (Tn) {$T_n$} };
\end{tikzpicture}
\end{document}
Edit (2): Thank to @cfr, which pointed me to simple solution: your line
child { edge from parent[draw=none] node[draw=none] (ellipsis) {$\ldots$} }
reorder to
child {node[draw=none] {$\ldots$} edge from parent[draw=none]}
and you will get desired results. Deep explanation you can find in cfr answer. It is very instructive.
I present two solutions. The first uses the standard TikZ tree syntax. The second uses the powerful tree-drawing package, forest.
TikZ
The problem has nothing to do with the fact that you are not drawing the edge. The problem is that you cannot modify the edge from parent
style in that way. edge from parent
is both and edge
drawing operation and a style. The code in the question confuses the two, but this is easier to explain with examples.
To see this, just change the line
child { edge from parent[draw=none] node[draw=none] (ellipsis) {$\ldots$} }
to
child { edge from parent[draw=green] node[draw=none] (ellipsis) {$\ldots$} }
Clearly, this is not the right way to go about this. edge from parent
is an edge
drawing operation and a style
and we want to change the style. But we cannot change a TikZ style (typically, anyhow) by saying <style name>[<new options>]
. This isn't the right syntax. Instead, we'd normally say something like
<style name>/.style={<new options>}
or
<style name>/.append style={<new options>}
or, in some cases,
<style name>={<new options>}
but we can only use these things inside \tikzset{}
or somewhere else that TikZ expects a style to be given.
In the case of a child path, TikZ expects to find edge from parent
operation at the end. If we put a node after it, TikZ assumes we want to create a label on the path and, by default, this is placed midway. If the node is supposed to be the node in the tree, it needs to come after the edge
, just as in other cases of drawing edges in TikZ.
So,
child { node[draw=none] (ellipsis) {$\ldots$} edge from parent[draw=green] }
produces
and
child { node[draw=none] (ellipsis) {$\ldots$} edge from parent[draw=green] node [draw=none, font=\scriptsize] {label} node [font=\scriptsize, at end, draw=none] {end label} }
produces
And, of course,
child { node[draw=none] (ellipsis) {$\ldots$} edge from parent[draw=none] }
produces
If we prefer to specify this wherever, we can do so, but we need to make sure that the edge from parent
operation still comes at the end. This is the default, so not using it does the trick. We can still change its style, provided we just change its style. For example,
child { [edge from parent/.style={draw=none}] node[draw=none] (ellipsis) {$\ldots$} }
will produce the same output.
For convenience, and to please Zarko, we can create a forest-alike style which does this more easily:
no edge/.style={
edge from parent/.append style={draw=none}
}
and then say
child { [no edge] node [draw=none] (ellipsis) {$\ldots$} }
to produce the required result.
Making the example complete,
\documentclass[border=10pt,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
[
every node/.style={circle, draw},
no edge/.style={
edge from parent/.append style={draw=none}
}
]
\node (r) {$r$}
child { node (T1) {$T_1$} }
child { [no edge] node [draw=none] (ellipsis) {$\ldots$} }
child { node (Tn) {$T_n$} };
\end{tikzpicture}
\end{document}
produces
Forest
If you are willing to use a different package, forest has a no edge
option which does what it says on the tin for whichever node(s) you apply it to.
For example:
\usepackage{forest}
\forestset{
forest circles/.style={
for tree={
math content,
draw,
circle,
minimum size=20pt,
inner sep=0pt,
text centered
},
no edge/.append style={draw=none}
},
}
\begin{document}
\begin{forest}
forest circles,
[r
[T_1]
[\cdots, no edge]
[T_n]
]
\end{forest}
\end{document}