马尔可夫链箭头和标签堆叠在一起

马尔可夫链箭头和标签堆叠在一起

我面临以下挑战:

  1. 我的底部链条箭头和标签(1- \theta)堆叠在一起/重叠,这是我不喜欢的,并且
  2. 我想添加一条额外的虚线,该虚线位于左侧​​并标记 \theta在顶部,如下图所示:
    期望输出
    以下是我的 MWE:
\documentclass{book}

\usepackage{tikz}
\usetikzlibrary{automata,arrows,positioning,calc}

\begin{document}
Markov chain:   
\begin{center}
            \begin{tikzpicture}[->, >=stealth', auto, semithick, node distance=3cm]
                \tikzstyle{every state}=[fill=white,draw=black,thick,text=black,scale=1]
                \node[state]    (A)                     {$0$};
                \node[state]    (B)[right of=A]   {$1$};
                \node[state]    (C)[right of=B]   {$2$};
                \node[state]    (D)[right of=C]   {$3$};
                \path
                (A) edge[loop left]         node{$1-\theta$}    (A)
                (B) edge[bend left,below]   node{$1-\theta$}    (A)
                edge[bend left,above]       node{$\theta$}  (C)
                (C) edge[bend left,below]   node{$1-\theta$}    (A)
                edge[bend left,above]       node{$\theta$}  (D)
                (D) edge[bend left,below]   node{$1-\theta$}    (A);
                %\node[above=0.5cm] (A){Patch G};
                %\draw[red] ($(D)+(-1.5,0)$) ellipse (2cm and 3.5cm)node[yshift=3cm]{Patch H};
            \end{tikzpicture}
        \end{center}

\end{document}

答案1

一种可能的方法是这样的:

在此处输入图片描述

%\documentclass{book}
\documentclass[border=3.141592]{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata,
                bbox,
                chains, 
                positioning,
                quotes}

\begin{document}
%Markov chain:
%\begin{center}
    \begin{tikzpicture}[auto=right, 
                        bezier bounding box,
     node distance = 22mm,
       start chain = going right, 
 every edge/.style = {draw, -Stealth, semithick},
every state/.style = {draw, thick, on chain}
                        ]
    \begin{scope}[nodes=state]
\node (A)   {$0$};
\node (B)   {$1$};
\node (C)   {$2$};
\node (D)   {$3$};
\coordinate (E);
    \end{scope}
%
\path   (A) edge[loop left, looseness=12,  "$1-\theta$" '] (A);
\path[bend left, swap] 
        (A) edge["$\theta$"]    (B)
        (B) edge["$\theta$"]    (C)
        (C) edge["$\theta$"]    (D)
        (C) edge["$\theta$"]    (D)
        (D) edge[dashed, "$\theta$"]  (E);
\path[out=210]
        (B) edge[in=-30, "$1-\theta$"]  (A)
        (C) edge[in=-45, "$1-\theta$"]  (A)      
        (D) edge[in=-60, "$1-\theta$"]  (A);
            \end{tikzpicture}
%\end{center}
\end{document}

答案2

这里有一个选项tikz-cd

在此处输入图片描述

如果您更喜欢1-\theta箭头上方的标签,您可以更改"1-\theta", pos=.25"1-\theta"'

\documentclass{article}

\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}[column sep=2cm, arrows={-Stealth}, cells={nodes={draw, circle, minimum size=8mm}}]
    0\arrow[r, bend left, "\theta"]\arrow[loop left, "1-\theta"]
    & 1\arrow[r, bend left, "\theta"]\arrow[l, bend left, "1-\theta", pos=.25]
    & 2\arrow[r, bend left, "\theta"]\arrow[ll, bend left, "1-\theta", pos=.25]
    & 3\arrow[r, dashed, bend left, "\theta"] \arrow[lll, bend left, "1-\theta", pos=.25]
    & |[draw=none]|
\end{tikzcd}

\end{document}

相关内容