TikZ를 사용하여 SIRS 다이어그램에 화살표 그리기

TikZ를 사용하여 SIRS 다이어그램에 화살표 그리기

다음과 같은 SIRS(Susceptible-Infectious-Recovered-Susceptible) 다이어그램을 만들려고 합니다. 여기에 이미지 설명을 입력하세요

거의 다 왔어요. 복구됨에서 민감성으로 가는 위쪽 화살표를 제외한 모든 항목이 있습니다. 내 현재 코드는 다음과 같습니다.

\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{positioning, arrows.meta}

\begin{document}

\begin{tikzpicture}[
    node distance=2.5cm,
    arrow/.style={->, >=Stealth, thick},
    box/.style={draw, rectangle, rounded corners, minimum width=2cm, minimum height=1cm, align=center}
]

% Nodes
\node[box] (S) {Susceptible};
\node[box, right=of S] (I) {Infectious};
\node[box, right=of I] (R) {Recovered};

% Arrows
\draw[arrow] (S) -- node[above]{$\beta$} (I);
\draw[arrow] (I) -- node[above]{$\gamma$} (R);

\end{tikzpicture}

\end{document}

그리고 내 코드가 생성하는 내용은 다음과 같습니다. 여기에 이미지 설명을 입력하세요

복구됨에서 감염 가능으로 화살표를 그리는 데 문제가 있습니다. 상자와 겹치지 않고 위로 이동하도록 화살표를 그리는 방법은 무엇입니까? 어떤 도움이라도 대단히 감사하겠습니다.

답변1

나의 원래 순진한 시도는 다음과 같습니다.

\node (A) [above=0.5cm of I] {$\delta$};
\draw[arrow] (R.north) |- (A.south) -| (S.north); 

사용자 Sandy G는 놀라울 정도로 연구하기 어려운 기술을 사용하는 더 나은 옵션을 제공합니다(인터넷 검색이 --++어렵다는 것이 밝혀졌습니다). 나는 그것에 대해 이야기하는 이 오래된(11년) 게시물을 찾았습니다.TiKz 대시 대시 플러스 플러스 TikZ 매뉴얼 섹션으로 이동했습니다.13.4 상대 및 증분 좌표

++새 경로 좌표 이전을 사용하여 경로에서 이전 좌표를 기준으로 상대 좌표를 지정할 수 있습니다 . 매뉴얼에서:

좌표 앞에 ++를 붙여 "상대적"으로 만들 수 있습니다. ++(1cm,0pt)와 같은 좌표는 "이전 위치에서 오른쪽으로 1cm, 이를 새로운 현재 위치로 한다"는 의미입니다. 상대 좌표는 "로컬" 컨텍스트에서 유용한 경우가 많습니다.

이렇게 하면 다음과 같이 쉬워집니다.

\draw[arrow] (R.north) -- ++(0,0.5) -| (S.north) node[above, pos=0.25] {$\delta$};

이는 노드 R의 북쪽에서 0.5 위로 노드를 그린 다음 S의 북쪽에 연결하지만 거기에 도달하기 위해 급회전합니다( 로 지정됨 -|). 노드는 경로(대칭)보다 0.25 위에 배치되고 $\delta$.

MWE

두 답변 모두 거의 동일한 이미지를 제공하지만 다양한 관점을 보는 것을 좋아할 것이라고 생각했습니다.

MWE:

\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{positioning, arrows.meta}

\begin{document}

\begin{tikzpicture}[
    node distance=2.5cm,
    arrow/.style={->, >=Stealth, thick},
    box/.style={draw, rectangle, rounded corners, minimum width=2cm, minimum height=1cm, align=center}
    ]

    % Nodes
    \node[box] (S) {Susceptible};
    \node[box, right=of S] (I) {Infectious};
    \node[box, right=of I] (R) {Recovered};

    % Arrows
    \draw[arrow] (S) -- node[above]{$\beta$} (I);
    \draw[arrow] (I) -- node[above]{$\gamma$} (R);

    % My Naive Attempt
    % \node (A) [above=0.5cm of I] {$\delta$};
    % \draw[arrow] (R.north) |- (A.south) -| (S.north);

    % Sandy G's code
    \draw[arrow] (R.north) -- ++(0,.5) -| (S.north) node[above, pos=0.25] {$\delta$};
        
\end{tikzpicture}

\end{document}

관련 정보