从矩形的一侧到另一侧画一条直角边

从矩形的一侧到另一侧画一条直角边

基本上,我正在尝试使用 Tikz 复制下面的图表。

RNN 单元

我已经通过 MWE 走到这一步了。

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
    shorten >=1pt,->,
    draw=black!50,
    node distance=2.5cm,
    %
    input/.style={draw=black, circle, fill=black!30, minimum size=1cm},
    cell/.style={draw=black, rectangle, rounded corners=3mm, minimum width=3cm,
                 minimum height=1.5cm, fill=black!10},
    %
    pre/.style={->, semithick},
    post/.style={<-, semithick}
    ]

    \node[cell]  (cell)   at (0,0)        {$R$};
    \node[input] (input)  [below of=cell] {$x_t$} edge[pre] (cell);
    \node[input] (output) [above of=cell] {$h_t$} edge[post] (cell);
    %
    \draw[pre, bend right=90, rounded corners=5pt] (cell.east) to (cell.west);

\end{tikzpicture}
\end{document}

我自己的尝试

我无法实现的是从矩形右侧到左侧的直角箭头。因此,我甚至还没有尝试过从 A 到 h_t 的箭头中的“跳跃”。

答案1

这是提供您想要实现的图像的代码。您可以使用精确的坐标和线宽来玩。

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
    shorten >=1pt,
    draw=black!50,
    node distance=2.5cm,
    %
    input/.style={draw=black, circle, fill=black!30, minimum size=1cm},
    cell/.style={draw=black, rectangle, rounded corners=3mm, minimum width=3cm,
                 minimum height=1.5cm, fill=black!10},
    %
    pre/.style={->, semithick},
    post/.style={<-, semithick}
    ]

    \node[cell]  (cell)   at (0,0)        {$R$};
    \node[input] (input)  at (0,-3) {$x_t$} edge[pre] (cell);
    \node[input] (output) at (0,3) {$h_t$} edge[post] (cell);
    %
    \draw[rounded corners=5pt] (cell.east) -- (3,0) -- (3,2) -- (0.2,2);
    \draw[rounded corners=5pt,->] (-0.2,2) -- (-3,2) -- (-3,0) -- (cell.west);

\end{tikzpicture}
\end{document}

在此处输入图片描述

更新

这更接近您的原始图像。

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
    shorten >=1pt,
    draw=black,
    node distance=2.5cm,line width=2pt,
    %
    input/.style={draw=black, circle, fill=black!30, minimum size=1cm},
    cell/.style={draw=black, rectangle, rounded corners=3mm, minimum width=3cm,
                 minimum height=1.5cm, fill=black!10},
    %
    pre/.style={->},
    post/.style={<-}
    ]

    \node[cell]  (cell)   at (0,0)        {$A$};
    \node[input,fill=cyan!40] (input)  at (0,-3) {$x_t$} edge[pre] (cell);
    \node[input,fill=violet!40,line width=2pt] (output) at (0,3) {$h_t$} edge[post] (cell);
    %
    \draw[rounded corners=5pt] (cell.east) -- (3,0) -- (3,2) -- (0.2,2);
    \draw[rounded corners=5pt,->] (-0.2,2) -- (-3,2) -- (-3,0) -- (cell.west);

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容