TransWikia.com

Combine nodes and arrows in a tikzset

TeX - LaTeX Asked by LudiWin on November 19, 2020

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!

One Answer

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.

Correct answer by abcdefg on November 19, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP