TikZ 旋转无意中移动了节点

TikZ 旋转无意中移动了节点

我正在尝试说明一些输入(时间序列)进入模型。箭头应该位于点下方的中心。我用它positioning来获得正确的相对位置。如果我旋转箭头,它会移位。我如何旋转但“重新居中”箭头?提前致谢!

下面是 MWE。

插图

\documentclass[tikz,border=2mm]{standalone} 

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathreplacing,angles,quotes}
\usetikzlibrary{shapes.geometric,shapes.arrows}
\usetikzlibrary{shadows}

\begin{document}

\tikzset{%
    input_circle/.style={%
        draw,
        circle,
        minimum size=1.3cm,
        fill=yellow,
        font=\small
    },
    solid_box/.style={%
        draw,
        thick,
        centered
    },
    cascaded/.style={%
        solid_box,
        double copy shadow={
            shadow xshift=-1ex,
            shadow yshift=1ex
        }
    },
    big_arrow/.style={%
        single arrow,
        draw,
        fill=gray
    }
}
\begin{tikzpicture}

    \node (r_t_k) at (0,0) [input_circle] {$r_{t-k}$};
    \node (r_t_k_1) [input_circle,right=0.5cm of r_t_k] {$r_{t-k+1}$};
    \node (dots) [minimum size=2cm,right=0.5cm of r_t_k_1] {\huge $\cdots$};
    \node (r_t_1) [input_circle,right=0.5cm of dots] {$r_{t-1}$};
    \node (r_t) [input_circle,right=0.5cm of r_t_1] {$r_t$};

    \node (arrow1) [big_arrow,rotate=-90,below=0.2cm of dots.south] {a};

    % lstm
    \node (lstm) [cascaded, minimum width=6cm, minimum height=1.5cm, fill=orange, below=1cm of arrow1] {\Large LSTM};

\end{tikzpicture}

\end{document}

答案1

尝试仅旋转形状边框:

\node (arrow1) [big_arrow,shape border rotate=270, below=0.2cm of dots.south] {a};

考虑您的 MWE 中的此代码行给出:

在此处输入图片描述

编辑: 完整的、稍微缩短你的 MWE,可以是:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,
                chains,
                decorations.pathreplacing,
                positioning,
                quotes,
                shadows, shapes.arrows, shapes.geometric,}

\begin{document}

\tikzset{%
    input_circle/.style={%
        draw,
        circle,
        minimum size=1.3cm,
        fill=yellow,
        font=\small
    },
    cascaded/.style args={#1/#2/#3}{%
        draw,
        thick,
        fill=#3,
        minimum width=#1,
        minimum height=#2,
        double copy shadow={
            shadow xshift=-1ex,
            shadow yshift=1ex
        }
    },
    big_arrow/.style={
        single arrow,
        draw,
        fill=gray,
        minimum height=2em,
    }
}
    \begin{tikzpicture}[node distance = 8mm and 5mm]
\node (r_t_k)   [input_circle]                      {$r_{t-k}$};
\node (r_t_k_1) [input_circle,right=of r_t_k]       {$r_{t-k+1}$};
\node (dots)    [minimum size=2cm,right=of r_t_k_1] {\huge $\cdots$};
\node (r_t_1)   [input_circle,right=of dots]        {$r_{t-1}$};
\node (r_t)     [input_circle,right=of r_t_1]       {$r_t$};

\node (arrow1)  [big_arrow, shape border rotate=270, below=of dots.center] {a};

\node (lstm)    [cascaded=6cm/1.5cm/orange, below=of arrow1] {\Large LSTM};
    \end{tikzpicture}
\end{document}

附註: 另一个可能性是,您希望将箭头的内容旋转。在这种情况下,您可以使用rotate around选项:

\begin{document}
% preamble
    \begin{tikzpicture}[node distance = 6mm and 5mm]
\node (r_t_k)   [input_circle]                      {$r_{t-k}$};
\node (r_t_k_1) [input_circle,right=of r_t_k]       {$r_{t-k+1}$};
\node (dots)    [minimum size=13mm,right=of r_t_k_1] {\huge $\cdots$};
\node (r_t_1)   [input_circle,right=of dots]        {$r_{t-1}$};
\node (r_t)     [input_circle,right=of r_t_1]       {$r_t$};

\coordinate[below=of dots] (aux);
\node (arrow1)  [big_arrow, 
                 rotate around={270:(0,0)},
                 at={(aux)}]  {a};
\node (lstm)    [cascaded=6cm/1.5cm/orange, 
                 below=12mm of aux] {\Large LSTM};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

另一种方法是分别处理位置和节点内容,使用:

\coordinate[below=0.2cm of dots.south] (arrow1);
\node at (arrow1) [big_arrow,rotate=-90] {a};

代替

\node (arrow1) [big_arrow,rotate=-90,below=0.2cm of dots.south] {a};

看 :

\documentclass[tikz,border=2mm]{standalone} 

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathreplacing,angles,quotes}
\usetikzlibrary{shapes.geometric,shapes.arrows}
\usetikzlibrary{shadows}

\begin{document}

\tikzset{%
    input_circle/.style={%
        draw,
        circle,
        minimum size=1.3cm,
        fill=yellow,
        font=\small
    },
    solid_box/.style={%
        draw,
        thick,
        centered
    },
    cascaded/.style={%
        solid_box,
        double copy shadow={
            shadow xshift=-1ex,
            shadow yshift=1ex
        }
    },
    big_arrow/.style={%
        single arrow,
        draw,
        fill=gray
    }
}
\begin{tikzpicture}

    \node (r_t_k) at (0,0) [input_circle] {$r_{t-k}$};
    \node (r_t_k_1) [input_circle,right=0.5cm of r_t_k] {$r_{t-k+1}$};
    \node (dots) [minimum size=2cm,right=0.5cm of r_t_k_1] {\huge $\cdots$};
    \node (r_t_1) [input_circle,right=0.5cm of dots] {$r_{t-1}$};
    \node (r_t) [input_circle,right=0.5cm of r_t_1] {$r_t$};

    \coordinate[below=0.2cm of dots.south] (arrow1);
    \node at (arrow1) [big_arrow,rotate=-90] {a};
    
    % lstm
    \node (lstm) [cascaded, minimum width=6cm, minimum height=1.5cm, fill=orange, below=1cm of arrow1] {\Large LSTM};

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容