Related: Problem with "append after command" and "insert path", but I did not understand how to apply the solutions there in my case.
I'm defining a simple tikz style which uses append after command:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,fit}
\begin{document}
\begin{tikzpicture}[
fit after/.style={
append after command={%
node[draw, inner sep=0pt, fit=(\tikzlastnode)] {}
}
}
]
\node[fit after] {A};%%%% WORKS
\node {B} child { node[fit after] {C} }; %%%% FAILS
\end{tikzpicture}
\end{document}
On the first node (A), it works fine and draws a rectangle around it.
On the C node, however, I get the following error message:
Package pgf Error: No shape named is known.
The \tikzlastnode isn't at fault, as even hardcoding the name of the node still fails in the child case.
Is the child path operation messing with append after command? Is there a workaround?
Context: I am trying to make a triangle fit whole subtree command, which draws a triangle that fits around all the nodes in the subtree.

forestpackage you would use in this case? Do you mean thatappend after commandwould work better withforest? I skimmed over the documentation, but nothing stroke me. Thanks! – Suzanne Soy Jun 09 '16 at 22:50fit. I doubtappend after commandwould work straightforwardly because it would probably conflict with Forest's own functions. But the point is that you don't really need it with Forest. (I'm not entirely sure how it would work in your example either, but I accept that you had something in mind. :-) ) – cfr Jun 09 '16 at 23:29