# tikz parameterized circle node with t-lines inside within a tree diagram

I would like to draw a tree diagram consisting of circle nodes with three subparts divided by a t-line (see sample below). Instead of separating every tree node by hand I would like to only specify the style of the node accompanied by at least three parameters (the fields inside the circle node drawing). I already achieved the following by putting the following by putting this stackexchange circle node with t-lines example into a style:

\tikzset{%
sectors/.style n args={5}{%
circle,
draw,
minimum width=#4,
append after command={
\pgfextra{
\draw (\tikzlastnode.center) -- (\tikzlastnode.south) ;
\draw (\tikzlastnode.west)   -- (\tikzlastnode.east) ;
\path (\tikzlastnode.center) -- node[#5] {#1} (\tikzlastnode.north);
\path (\tikzlastnode.center) -- node[#5] {#2} (\tikzlastnode.south west);
\path (\tikzlastnode.center) -- node[#5] {#3} (\tikzlastnode.south east);
}
}
}
}


This works fine as long as there is only one root node. But as soon as I want to draw children nodes tikz fails to compile sayiong "Error: No shape named is known. [...]". So the following does not work.

\begin{tikzpicture}[]

\node[sectors={0}{1}{1}{1.5cm}{}]{}%
child{
node [sectors={1}{2}{3}{1.5cm}{font=\bfseries}]{}
};%
\end{tikzpicture}


I already noticed that there are problems with using tex macros within tree structures but I was not able to find a solution through the answers given there. I have not specified a simple tex-macro but a parameterized style. Maybe under the hood this works similar but I am not a pro when it comes to tikz and therefore was not able to adapt the solutions to this case.

Any help would be appreciated.

Here you see an outline of the tree structure I want to achieve:

append after command uses a similar approach for saving the node’s name as the tree uses to connect the nodes. For this, I borrow most of the code from a label or a pin and apply it in your example, too. I am using edges here since with your \pgfextra example, you would also need the additional \pgfinterruptpath.

Unfortunately, both implementations do not inherit the style from the node. The path picture does this if I recall correctly but is very impractical in combination with transformations and you cannot use the node’s anchors.

For the best experience it would be best to implement this as a separate shape (at least the lines inside the circle).

## Code

\documentclass[tikz]{standalone}
\makeatletter
\tikzset{
sectors/.style n args={5}{
shape=circle, draw, minimum width={#4},
append after command={%
\bgroup
[current point is local = true]
\pgfextra{\let\tikz@save@last@fig@name=\tikz@last@fig@name}
{[-,shorten >=+.5\pgflinewidth, shorten <=+.5\pgflinewidth]
(\tikzlastnode.west)   edge (\tikzlastnode.east)
(\tikzlastnode.center) edge (\tikzlastnode.south)
[every edge/.style=]   edge node[#5] {#1} (\tikzlastnode.north)
edge node[#5] {#2} (\tikzlastnode.south west)
edge node[#5] {#3} (\tikzlastnode.south east)
}
\pgfextra{\global\let\tikz@last@fig@name=\tikz@save@last@fig@name}
\egroup}}}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[sectors={0}{1}{1}{1.0cm}{}] {}%
child{
node [sectors={1}{2}{3}{1.0cm}{font=\bfseries}] {}
};
\end{tikzpicture}
\end{document}

• Thanks! At least it is compiling now. But unfortunately the children nodes now overlap... – boris Dec 7 '13 at 22:22
• @boris They should overlap eitherway. You need to adjust the sibling distance. Other packages like forest and tikz-qtree use TikZ but place the nodes in a way so that they not overlap. The trees of TikZ are very primitive in that way. – Qrrbrbirlbel Dec 7 '13 at 23:01
• Unfortunately tikz seems to ignore the sibling distance directive. However I'll mark your answer as right then. – boris Dec 7 '13 at 23:16
• @boris It works for me if given as an option to the TikZ picture, the path, a child or before the children, but not as a node option. – Qrrbrbirlbel Dec 7 '13 at 23:24