Tikz:两个边路径连接

Tikz:两个边路径连接

是否有可能存在两条边的路径,如下图所示?

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\tikzstyle{status} = [rectangle, draw=black, text centered, anchor=north, text=black, minimum width=2em, minimum height=2em, node distance=6ex and 7em, font=\bfseries]
\tikzstyle{line} = [draw,thick,-latex]
\tikzstyle{transition} = [font=\small]

\begin{tikzpicture}
\node [status, fill=green] (T) {H};
\node [status, fill=red, right=5em of T] (A) {A};
\node [status, fill=gray, right=5em of A] (D) {D};

\path [line] (T) -- (A) node[transition,pos=0.5,above,align=left] {$\#A \geq 1$};
\path [line] (A) -- (D) node[transition,pos=0.5,above,align=left] {wait $\tau$ tick\\$\tau\sim\mathcal{G}(\lambda)$};
%\path [line] (D) -| (T) node[transition,pos=0.83,left] {$p_{repl}$};
\end{tikzpicture}

\end{document}

截屏

我多么希望如此:

小样

答案1

您可以使用类似如下的方法:

\path [line] (D) -- ++(0,-30pt) -| (T) node[transition,pos=0.83,left] {$p_{repl}$};

在此处输入图片描述

完整代码:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\tikzstyle{status} = [rectangle, draw=black, text centered, anchor=north, text=black, minimum width=2em, minimum height=2em, node distance=6ex and 7em, font=\bfseries]
\tikzstyle{line} = [draw,thick,-latex]
\tikzstyle{transition} = [font=\small]

\begin{tikzpicture}
\node [status, fill=green] (T) {H};
\node [status, fill=red, right=5em of T] (A) {A};
\node [status, fill=gray, right=5em of A] (D) {D};

\path [line] (T) -- (A) node[transition,pos=0.5,above,align=left] {$\#A \geq 1$};
\path [line] (A) -- (D) node[transition,pos=0.5,above,align=left] {wait $\tau$ tick\\$\tau\sim\mathcal{G}(\lambda)$};

\path [line] (D) -- ++(0,-30pt) -| (T) node[transition,pos=0.83,left] {$p_{repl}$};
\end{tikzpicture}

\end{document}

相关内容