# Inheritance in Tikz tree

As I read the rule for style inheritance in a tree (pgfmanual 18.4, page 215), the naked [rect] below should mean that the node labeled "empty" be rectangular. But it's not. What am I doing wrong?

Thanks.

\begin{tikzpicture}[->,sibling distance=7mm, level distance=5mm,
rect/.style={inner sep=0pt,minimum size=2mm,draw,rectangle},
alive/.style={fill=orange,draw},
emph/.style={thick,yellow}]
\node[rect] (MRCA) at (2.5,4) {}
[rect]
child {node[alive](high){}
child {node {empty}
}
}
;
\end{tikzpicture}

-
You cannot certain node options (most oft them) in the path but must set them in the node options. every child node/.append style=rect should help here. –  Qrrbrbirlbel Aug 27 '13 at 6:45

As said by Qrrbrbirlbel in his comment, the problem lies in the kind of options you want to pass to the nodes within the path construction.

For example, if you try to pass to the \path an inner sep option, this will not have any effect.

Notice that you have at least a couple of ways to proceed:

1. via every child node as Qrrbrbirlbel was suggesting
2. via every node.

These are very different methods as one, the latter, would affect also the initial node of the tree while the former doesn't (and it is something one should keep in mind).

A demonstration example:

\documentclass[tikz,border=2pt,png]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[->,sibling distance=7mm, level distance=5mm,
rect/.style={inner sep=0pt,minimum size=2mm,draw},
alive/.style={fill=orange,draw},
emph/.style={thick,yellow}
]

\path[every child node/.style={rect,inner sep=3pt}]% global setting applied to the whole path
[inner sep=30pt]% this option does not have effect
node[rect](MRCA) at (0,4) {}% without rect definition here, this not won't inherit the style
child { node[alive](high){}
child { node {empty}
}
}
;

\path[every node/.style={rect,inner sep=3pt}]% global setting applied to the whole path
[inner sep=30pt]% this option does not have effect
node[circle](MRCA) at (2.5,4) {} %the circle option has effect
child { node[alive](high){}
child { node {empty}
}
}
;

% initial OP's code
\node[rect] (MRCA) at (5,4) {}
[rect]
child {node[alive](high){}
child {node {empty}
}
}
;
\end{tikzpicture}
\end{document}


The result:

-

I don't find the manual's explanation completely clear either. But the point is that child is a path operation and an option xx placed at the following point

\node {root}
[xx]
child ...


applies to all the child paths. Now some options to paths get inherited by nodes on those paths, others do not. For example a colour blue in \draw[blue] (0,0) -- (1,0) node {x}; will apply both to the path and the node; whereas \draw[rectangle] (0,2) -- (1,2) node {x}; will not have any effect. Node styles can be passed via every node/.style:

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[blue] (0,2) -- (1,2) node {x};
\draw[rectangle,draw] (0,1) -- (1,1) node {x};
\draw[every node/.style={rectangle,draw}] (0,0) -- (1,0) node {x};
\end{tikzpicture}

\end{document}


Similarly in your example there is an every child node/.style that can be used.

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[->,
rect/.style={inner sep=2pt,minimum size=2mm,draw,rectangle},
brect/.style={inner sep=2pt,minimum size=2mm,draw,rectangle,blue},
alive/.style={fill=orange,draw}]
\node[rect] at (2.5,4) {}
[blue]
child {node[alive] {}
child {node {empty}
}
}
;
\node[rect] at (5.5,4) {}
[every child node/.style=rect]
child {node[alive] {}
child {node {empty}
}
}
;
\node[rect] at (8.5,4) {}
[brect]
child {node[alive] {}
child {node {empty}
}
}
;
\end{tikzpicture}

\end{document}


Notice how the brect style that contains a shape plus the colour blue, when applied to a path just passes on the colour.

-