將節點和箭頭合併到 tikzset 中

將節點和箭頭合併到 tikzset 中

我想知道是否可以在共享 tikzset 中組合節點和箭頭(僅根據“父節點”的位置定義)?

一個最小的工作示例如下:

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

我不想定義額外的繪製命令來繪製小圓圈,而是想以某種方式將繪製命令移到定義中\tikzset{LSTMCell/.style={...}}

這樣的事情可能嗎?

提前謝謝了!

答案1

您可以將任何您喜歡的內容新增到節點的定義中。其工作原理如下:

  1. 定義一個pic包含您要新增的內容的;
  2. 透過將 新增pic到節點的定義中append after command

明確的例子:

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

在此輸入影像描述

顯然,如果您使用 ,箭頭會看起來更好bending

相關內容