[Tex/LaTex] Style inheritance in TikZ trees

nodestikz-pgftikz-stylestikz-trees

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}

Best Answer

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:

Demonstration output

\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.

Sample output

\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.