Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tikz: two edge path

Tags:

latex

tikz

Can I use \path to draw a line that goes through 2 edges.

Consider:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\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{document}
    \begin{tikzpicture}
    \node [status, fill=green] (T) {H};
    \node [status, fill=red, right=4em of T] (A) {A};
    \node [status, fill=gray, right=4em 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}

Screenshot:

screenshot

Mockup of what I want:

mockup

like image 899
Ricardo Magalhães Cruz Avatar asked Oct 20 '22 08:10

Ricardo Magalhães Cruz


1 Answers

Easier than we thought, you can make it substituting the commented line (line number 17) in your code with:

\path [line] (D) -- ++(0,-1) -- +(-4.25,0) -- (T) node[transition,pos=0.3,right] {$p_{repl}$};

The output:

screenshot of the output pdf

Improvement: even better, using -| and then one aux point only instead of two (one is needed):

\path [line] (D) -- ++(0,-1) -| (T) node [transition,pos=0.8,left] {$p_{repl}$};
like image 65
MattAllegro Avatar answered Oct 28 '22 16:10

MattAllegro