TikZ 圖中的複製與鏡像內容

TikZ 圖中的複製與鏡像內容

我有下圖,是在 TikZ 中製作的:

在此輸入影像描述

這是它的程式碼:

\documentclass[tikz,border=2mm]{standalone} 
\usetikzlibrary{positioning, fit, arrows.meta}

\begin{document}

\begin{tikzpicture}[
    prod/.style={circle, draw, inner sep=0pt, fill=black!5, black!20},
    ct/.style={circle, draw, inner sep=5pt, ultra thick, minimum width=10mm, fill=black!5, black!20},
    ft/.style={circle, draw, minimum width=8mm, inner sep=1pt, fill=black!5, black!20},
    filter/.style={circle, draw, minimum width=7mm, inner sep=1pt, fill=black!5, black!20},
    mylabel/.style={font=\scriptsize\sffamily},
    >=LaTeX
    ]

\node[ct, label={[mylabel, black!20]Memory cell}, fill=black!5] (ct) {};
\node[filter, right=of ct, fill=black!5] (int1) {$f_g$};
\node[prod, right=of int1, fill=black!5] (x1) {$\times$}; 
\node[right=of x1] (ht) {$h_t$};
\node[prod, left=of ct, fill=black!5] (x2) {$\times$}; 
\node[filter, left=of x2, fill=black!5] (int2) {$f_h$};
\node[prod, below=5mm of ct, fill=black!5] (x3) {$\times$}; 
\node[ft, below=5mm of x3, label={[mylabel, black!20]right:Forget gate}, fill=black!5] (ft) {$f_t$};
\node[ft, above=of x2, label={[mylabel, black!20]left:Input gate}, fill=black!5] (it) {$f_t$};
\node[ft, above=of x1, label={[mylabel, black!20]left:Output gate}, fill=black!5] (ot) {$f_t$};

\foreach \i/\j in {int2/x2, x2/ct, ct/int1, int1/x1, x1/ht, it/x2, ct/it, ct/ot, ot/x1, ft/x3}
    \draw[->, black!20] (\i)--(\j);

\draw[->, black!20] (ct) to[bend right=45] (ft);

\draw[->, black!20] (ct) to[bend right=30] (x3);
\draw[->, black!20] (x3) to[bend right=30] (ct);

\node[fit=(int2) (it) (ot) (ft), draw, inner sep=0pt] (fit) {};

\draw[<-] (fit.west|-int2) coordinate (aux)--++(180:7mm) node[left]{$x_t$};
\draw[<-, black!20] ([yshift=1mm]aux)--++(135:7mm);
\draw[<-, black!20] ([yshift=-1mm]aux)--++(-135:7mm);

\draw[<-] (fit.north-|it) coordinate (aux)--++(90:7mm) node[above]{$x_t$};
\draw[<-, black!20] ([xshift=1mm]aux)--++(45:7mm);
\draw[<-, black!20] ([xshift=-1mm]aux)--++(135:7mm);

\draw[<-] (fit.north-|ot) coordinate (aux)--++(90:7mm) node[above]{$x_t$};
\draw[<-, black!20] ([xshift=1mm]aux)--++(45:7mm);
\draw[<-, black!20] ([xshift=-1mm]aux)--++(135:7mm);

\draw[<-] (fit.south-|ft) coordinate (aux)--++(-90:7mm) node[below]{$x_t$};
\draw[<-, black!20] ([xshift=1mm]aux)--++(-45:7mm);
\draw[<-, black!20] ([xshift=-1mm]aux)--++(-135:7mm);

\end{tikzpicture}


\end{document}

現在我試圖「鏡像」一切,如下圖所示。這可能嗎? (不要介意鏡像字母,我不希望那些被鏡像,只是盒子內的圓圈和箭頭的結構)。

在此輸入影像描述

首先,即使建立顯示在第一個圖表下方的第二個圖表,我也遇到了麻煩。我嘗試使用外部 for 循環,但它根本不起作用。

編輯:由於符號 1 在下面提供了一個很好的答案,即使用 \Spy 創建範圍的副本,我想完善我的問題並補充說我希望能夠在兩個塊之間繪製箭頭(如在我手繪的圖片中看到紅色)。我嘗試在擁有 Spy 製作的副本時查找有關如何執行此操作的信息,但找不到任何內容。也許這是不可能的?

答案1

您可以透過以下方式取得範圍的免費副本\spy

\documentclass[tikz,border=2mm]{standalone} 
\usetikzlibrary{positioning, fit, arrows.meta,spy}

\begin{document}
    \begin{tikzpicture}[
                prod/.style={circle, draw, inner sep=0pt, fill=black!5, black!20},
                ct/.style={circle, draw, inner sep=5pt, ultra thick, minimum width=10mm, fill=black!5, black!20},
                ft/.style={circle, draw, minimum width=8mm, inner sep=1pt, fill=black!5, black!20},
                filter/.style={circle, draw, minimum width=7mm, inner sep=1pt, fill=black!5, black!20},
                mylabel/.style={font=\scriptsize\sffamily},
                >=LaTeX
            ]
        \begin{scope}[spy scope]
            \node[ct, label={[mylabel, black!20]Memory cell}, fill=black!5] (ct) {};
            \node[filter, right=of ct, fill=black!5] (int1) {$f_g$};
            \node[prod, right=of int1, fill=black!5] (x1) {$\times$}; 
            \node[right=of x1] (ht) {$h_t$};
            \node[prod, left=of ct, fill=black!5] (x2) {$\times$}; 
            \node[filter, left=of x2, fill=black!5] (int2) {$f_h$};
            \node[prod, below=5mm of ct, fill=black!5] (x3) {$\times$}; 
            \node[ft, below=5mm of x3, label={[mylabel, black!20]right:Forget gate}, fill=black!5] (ft) {$f_t$};
            \node[ft, above=of x2, label={[mylabel, black!20]left:Input gate}, fill=black!5] (it) {$f_t$};
            \node[ft, above=of x1, label={[mylabel, black!20]left:Output gate}, fill=black!5] (ot) {$f_t$};
            \foreach \i/\j in {int2/x2, x2/ct, ct/int1, int1/x1, x1/ht, it/x2, ct/it, ct/ot, ot/x1, ft/x3}
                \draw[->, black!20] (\i)--(\j);
            \draw[->, black!20] (ct) to[bend right=45] (ft);
            \draw[->, black!20] (ct) to[bend right=30] (x3);
            \draw[->, black!20] (x3) to[bend right=30] (ct);
            \node[fit=(int2) (it) (ot) (ft), draw, inner sep=0pt] (fit) {};
            \draw[<-] (fit.west|-int2) coordinate (aux)--++(180:7mm) node[left]{$x_t$};
            \draw[<-, black!20] ([yshift=1mm]aux)--++(135:7mm);
            \draw[<-, black!20] ([yshift=-1mm]aux)--++(-135:7mm);
            \draw[<-] (fit.north-|it) coordinate (aux)--++(90:7mm) node[above]{$x_t$};
            \draw[<-, black!20] ([xshift=1mm]aux)--++(45:7mm);
            \draw[<-, black!20] ([xshift=-1mm]aux)--++(135:7mm);
            \draw[<-] (fit.north-|ot) coordinate (aux)--++(90:7mm) node[above]{$x_t$};
            \draw[<-, black!20] ([xshift=1mm]aux)--++(45:7mm);
            \draw[<-, black!20] ([xshift=-1mm]aux)--++(135:7mm);
            \draw[<-] (fit.south-|ft) coordinate (aux)--++(-90:7mm) node[below]{$x_t$};
            \draw[<-, black!20] ([xshift=1mm]aux)--++(-45:7mm);
            \draw[<-, black!20] ([xshift=-1mm]aux)--++(-135:7mm);

            \spy [blue, size=10cm]on(0,0)in node[transform shape,yscale=-1]at(0,10);
        \end{scope}
    \end{tikzpicture}
\end{document}

相關內容