.png)
Relacionado:Problema con "añadir después del comando" e "insertar ruta", pero no entendí cómo aplicar las soluciones allí en mi caso.
Estoy definiendo un estilo tikz simple que usa 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}
En el primer nodo ( A
), funciona bien y dibuja un rectángulo a su alrededor.
Sin embargo, en el C
nodo aparece el siguiente mensaje de error:
Package pgf Error: No shape named is known.
No tiene \tikzlastnode
la culpa, ya que incluso codificar el nombre del nodo sigue fallando en el child
caso.
child
¿Está interfiriendo la operación de ruta append after command
? ¿Existe alguna solución?
Contexto: estoy intentando crear un triangle fit whole subtree
comando que dibuje un triángulo que se ajuste alrededor de todos los nodos del subárbol.
Respuesta1
Si forest
es una opción, es razonablemente sencillo definir un fit whole subtree
estilo. No recomiendo una forma triangular. Aunque experimenté un poco, esto inevitablemente parecía muy feo. Sin embargo, fit whole subtree
se pueden pasar las opciones que desee para diseñar el nodo. Por defecto, dibuja un rectángulo en rojo.
Tenga en cuenta que los usos múltiples de fit whole subtree
, incluidos los usos anidados, funcionan bien.
\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\usetikzlibrary{fit}
\begin{document}
\newcommand*\makenodename[1]{(#1)}
\forestset{
declare toks={fit these}{},
fit whole subtree/.style={
delay={
temptoksa=,
for tree={%
temptoksa+/.wrap pgfmath arg={ (##1)}{name()},
},
fit these/.register=temptoksa,
delay={
tikz+={
\node [draw=red, fit=\foresteoption{fit these}, inner sep=0pt, #1] {};
},
},
},
},
}
\begin{forest}
for tree={
fit=band,
child anchor=parent,
parent anchor=children,
}
[A
[B
[C, fit whole subtree
[D]
[E
[X]
[Y
[Z]
]
]
[F]
[G]
]
[H
[I
[J]
[K]
[L]
]
]
]
[M, fit whole subtree={thick, draw=blue, rounded corners}
[N
[O
[R]
]
[P]
[Q]
]
[S, fit whole subtree={green, densely dashed, rounded corners}
[T]
[U]
[V]
[W]
]
]
]
\end{forest}
\end{document}