如何使用 tikz 矩阵绘制指示不同节点的多个箭头

如何使用 tikz 矩阵绘制指示不同节点的多个箭头

如何使用 tikz 矩阵编写此图表?

在此处输入图片描述

答案1

纯 TiZ 解决方案,使用matrix of math nodes。最难的部分是绘制双箭头。最初我习惯于shift更改箭头的起点和终点,但这样做效果不佳,而且对于许多箭头来说这样做很麻烦。这里我使用@土拨鼠他在评论中的建议很有风格。

\documentclass[tikz]{standalone} 
\usetikzlibrary{decorations.markings,matrix,calc}
\newcommand\psr{\mathrm{PSR}}
\newcommand\pr{\mathrm{PR}}
\newcommand\pst{\mathrm{PST}}
\tikzset{ % Double arrow style thanks to marmot!
    shifted by/.style={
        to path={
            ($(\tikztostart)!#1!90:(\tikztotarget)$) -- ($(\tikztotarget)!#1!-90:(\tikztostart)$)
        }
    }, 
    shifted by/.default=2pt, 
    back and forth between/.style args={#1 and #2}{
        insert path={ 
            #1 edge[->,shifted by] #2 #2 edge[->,shifted by] #1
        }
    }
} 
\begin{document} 
\begin{tikzpicture}[>=stealth]
\matrix (m) [
    matrix of math nodes,
    row sep=1cm,
    column sep=1.5cm]
{%
\psr_0 & \pst_0 & \omega\pst_0\\
\psr_1 & \pst_1 & \omega\pst_1\\
\psr_2 & \pst_2 & \omega\pst_2\\
\pr_3  & \pst_3 & \omega\pst_3\\
       & \pst_4 & \omega\pst_4\\
};
\foreach \i in {1,2,3,4,5} \draw[->] (m-\i-2)--(m-\i-3);
\foreach \i [count=\j from 2] in {1,2,3,4} \draw[->] (m-\j-2)--(m-\i-2);
\foreach \i [count=\j from 2] in {1,2,3} {
    \draw[->] (m-\j-3)--(m-\i-3);
    \draw[back and forth between={(m-\i-1.south east) and (m-\j-2.north west)}];
    \draw (m-\i-1)--(m-\i-2);
}
\foreach \i [count=\j from 2] in {1,2} {
    \draw[->] (m-\j-1)--(m-\i-1);
    \draw[
        postaction=decorate,
        decoration={
            markings,
            mark=at position 0.5 with {
                \draw[-] (-3pt,-5pt)--(3pt, 5pt);
            }
        },
        ->
    ] (m-\j-3)--(m-\i-2);
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

@JouleV 的小修改回答. 没有该tikzdecorations.markings并使用canvas transform移动箭头:

\documentclass[tikz,margin=3pt]{standalone}
\usetikzlibrary{matrix}
\newcommand\psr{\mathrm{PSR}}
\newcommand\pr{\mathrm{PR}}
\newcommand\pst{\mathrm{PST}}

\begin{document}
\begin{tikzpicture}[>=stealth,
                    ]
\matrix (m) [
    matrix of math nodes,
    row sep=1cm,
    column sep=1.5cm]
{%
\psr_0 & \pst_0 & \omega\pst_0\\
\psr_1 & \pst_1 & \omega\pst_1\\
\psr_2 & \pst_2 & \omega\pst_2\\
\pr_3  & \pst_3 & \omega\pst_3\\
       & \pst_4 & \omega\pst_4\\
};
\foreach \i in {1,2,3,4,5}
    \draw[->] (m-\i-2)--(m-\i-3);
\foreach \i [count=\j from 2] in {1,2,3,4}
    \draw[->] (m-\j-2)--(m-\i-2);
\foreach \i [count=\j from 2] in {1,2,3} {
    \draw[->] (m-\j-3)--(m-\i-3);
    \draw[->,transform canvas={shift={( 1pt, 1pt)}}] (m-\i-1.south east)--(m-\j-2.north west);
    \draw[<-,transform canvas={shift={(-1pt,-1pt)}}] (m-\i-1.south east)--(m-\j-2.north west);
    \draw (m-\i-1)--(m-\i-2);
}
\foreach \i [count=\j from 2] in {1,2} {
    \draw[->] (m-\j-1)-- (m-\i-1);
    \draw[->] (m-\j-3)-- node[sloped] {/} (m-\i-2);
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容