Tikz builds the tree in such a way that the length level distance
is the distance between the point growth parent anchor
and the anchor of the child.
By default, the growth parent anchor
is center
. And the anchor of the children are the default nodes anchors, which are also center
. So you get 1cm between the centers of the nodes.
In order to have 1cm between the edges of the nodes as you request, you have to set growth parent anchor
to south
, and set also the default anchor
for all the nodes of the tree to north
. The following code implements this idea (and adds some blue lines to test if it works).
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[level distance=1cm, growth parent anchor={south}, nodes={anchor=north}]
\path node (a) {a}
child {
node (b) {b}
child {
node [align=center] (cd) {c \\ d}
child {
node (e) {e}
}
}
};
% Testing
\foreach \n in {a,b,cd} {
\draw[blue,<->] (\n.south) ++(2mm,0) -- ++(0, -1cm) node[midway, right]{1cm};
}
\end{tikzpicture}
\end{document}
It works! See the result:

Just a quick demonstration with Forest. The major advantages of Forest lie in its power, flexibility and concise syntax. Regularities in content and styling can be turned into automated configuration rules and trees themselves can be specified very concisely. Since Forest is based on TikZ, the power of the host package is also available.
For example,
\begin{forest}
bordered tree,
[
[x, border
[x1, acc, for descendants=border
[][][]
]
[x2, rej]
[x3, for children=border
[][][]
]
]
]
\end{forest}
specifies the target tree:

while the following partly explains the first and partly shows one or two additional tricks,
\begin{forest}
bordered tree,
[
[x, border, normal
[x1, acc, for descendants=border, label=left:\texttt{for descendants}
[][.,label=left:bordered children [][]][]
]
[x2, rej]
[x3, normal, for children=border, label=right:\texttt{for children}
[][.,label=right:unbordered children [][]][, for current and ancestors={edge+=blue}]
]
]
]
\end{forest}
which produces:

Complete code:
\documentclass[border=10pt]{standalone}
\usepackage{forest}
\forestset{
declare boolean={border}{0},
bordered tree/.style={
for tree={
minimum size=4mm,
inner sep=0.5mm,
edge+={semithick},
semithick,
},
before typesetting nodes={
where border={
edge+={dashed, draw},
}{},
where={isodd(n_children)}{
tempcounta/.process={
Ow+n {n children}{(##1+1)/2}
},
for n={
> R {tempcounta} % doesn't work to plug the above in directly ??'
}{calign with current edge},
}{},
where content={}{}{normal},
},
},
/tikz/.cd,
normal/.style={circle,draw},
invis/.style={draw=none},
acc/.style={circle,thick,draw=green!50,fill=green!2},
rej/.style={circle,thick,draw=red!50,fill=red!20},
}
\begin{document}
\begin{forest}
bordered tree,
[
[x, border
[x1, acc, for descendants=border
[][][]
]
[x2, rej]
[x3, for children=border
[][][]
]
]
]
\end{forest}
\begin{forest}
bordered tree,
[
[x, border, normal
[x1, acc, for descendants=border, label=left:\texttt{for descendants}
[][.,label=left:bordered children [][]][]
]
[x2, rej]
[x3, normal, for children=border, label=right:\texttt{for children}
[][.,label=right:unbordered children [][]][, for current and ancestors={edge+=blue}]
]
]
]
\end{forest}
\end{document}
Best Answer
You can use
Forest
package with a simple syntax to customize every edges of your tree, just insert edge options like thisComplete code