5

I have the following TikZ tree:

\begin{tikzpicture}[grow=south, level 1/.style={sibling distance=50pt}, level 3/.style={sibling distance=25pt}, level distance=30pt, every node/.style={draw, circle, inner sep=0pt, minimum size=5pt}, inner/.style={fill=black}]
    \node {}
        child {node[inner] {}
            child {node {} 
                child {node[inner] {}
                    child {node {}
                        child {node[inner] {}
                            child {node {}}
                        }
                        child {node[inner] {}
                            child{ node {}}
                        }
                    }
                }
                child {node[inner] {}
                    child {node {}}
                }
            }
        }
        child {node[inner] {}
            child {node {}
                child {node[inner] {}
                    child {node {}
                        child {node[inner] {}
                            child{ node {}}
                        }
                    }
                }
                child {node[inner] {}
                    child {node {}}
                }
            }
        }
        ;
\end{tikzpicture}

This leads to the following figure:

Tree

As you can see the black vertices ([inner]) have exactly one child node. What I need is that the edge to this unique child is very thick. Is there a neat way to do this, maybe within the inner/.style={...}?

1 Answer 1

5

I recommend switching to forest. There you can implement simple rules such as

where n children=1{<do something>}{<otherwise>}

However, looking at your tree it seems to me that the actual rule is

if={isodd(level)}{fill,for descendants={edge={very thick}}}{for descendants={edge={thin}}}

Anyway, I added both options. Please let me know if the true rule is different from both of them.

\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={grow=south,circle,draw,
where n children=1{fill,for descendants={edge={very thick}}}{for descendants={edge={thin}}},
}
[
 [
  [
   [
    [
     [[]]
     [[]]
    ]
   ]
   [[]]
  ]
 ]
 [
  [
   [[[[]]]]
   [[]]
  ]
 ]
]
\end{forest}
\begin{forest}
for tree={grow=south,circle,draw,
if={isodd(level)}{fill,for descendants={edge={very thick}}}{for descendants={edge={thin}}}
}
[
 [
  [
   [
    [
     [[]]
     [[]]
    ]
   ]
   [[]]
  ]
 ]
 [
  [
   [[[[]]]]
   [[]]
  ]
 ]
]
\end{forest}
\end{document}

enter image description here

1
  • Great answer! The second forest is the one that I need, since inner (black) vertices and outer (white) vertices should alternate. Having only one child is just a necessary condition.
    – ttnick
    Sep 17, 2019 at 14:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .