1

I was wondering whether it's possible to combine nodes and arrows (which are defined only in relation to the positioning of the "parent node") in a shared tikzset?

A minimum working example is the following:

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

Instead of defining an extra draw command to draw the little circle, I'd like to somehow move the draw command into the \tikzset{LSTMCell/.style={...}} definition.

Is something like that possible?

Many thanks in advance!

1 Answer 1

0

You can add anything you like to the definition of the node. This works as follows:

  1. define a pic that contains the stuff you want to add;
  2. add the pic to the definition of the node via append after command.

Explicit example:

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

enter image description here

Obviously the arrow would look better if you used bending.

1
  • Wonderful! Thanks a lot!
    – LudiWin
    Commented Nov 14, 2020 at 9:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .