我面临以下挑战:
\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}