
Me preguntaba si es posible combinar nodos y flechas (que se definen sólo en relación con la posición del "nodo principal") en un tikzset compartido.
Un ejemplo mínimo de trabajo es el siguiente:
\begin{tikzpicture}[node distance=2cm]
% \tikzset{arrow/.style={-latex, shorten >= 5pt, shorten <= 5pt}}
% \tikzset{diff/.style={-latex, shorten >= 5pt, shorten <= 5pt}}
% \tikzset{node/.style={draw, circle, fill, red, scale=0.25}}
\tikzset{LSTMCell/.style={draw, rectangle, red, scale=1.}}
\clip (-3,3) rectangle (10,-3);
\node (lstm0) [LSTMCell] at (0,0) {LSTM};
\draw [-latex, red, draw] ([xshift=-0.0cm]lstm0.185) arc[radius=0.4cm, start angle=90, end angle=360] node[midway, red, fill=white](){\scriptsize $c(t)$};
\end{tikzpicture}
En lugar de definir un comando de dibujo adicional para dibujar el círculo pequeño, me gustaría mover de alguna manera el comando de dibujo a la \tikzset{LSTMCell/.style={...}}
definición.
¿Es posible algo así?
¡Muchas gracias de antemano!
Respuesta1
Puedes agregar lo que quieras a la definición del nodo. Esto funciona de la siguiente manera:
- define un
pic
que contenga las cosas que deseas agregar; - agregue el
pic
a la definición del nodo medianteappend after command
.
Ejemplo explícito:
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\tikzset{pics/little arrow/.style={code={
\draw[red,-latex] (0,0) arc[radius=0.4cm, start angle=90, end angle=360]
node[midway, red, fill=white,font=\scriptsize ]{#1};
}},
LSTMCell/.style={draw, rectangle, red, scale=1.,
append after command={([xshift=-0.0cm]\tikzlastnode.185)
pic{little arrow={#1}}
}}}
\node (lstm0) [LSTMCell={$c(t)$}] at (0,0) {LSTM};
\end{tikzpicture}
\end{document}
Obviamente la flecha se vería mejor si usaras bending
.