我不熟悉 Tikz 包,以下代码是从同事的现有代码修改而来的。这是一个马尔可夫链图。我尽力了,但弯曲箭头从状态的中心开始,我希望它们从状态的边缘开始。还有其他方法吗?谢谢你的帮助!
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
%circle
\draw [thick] (-3.5,-1.6) circle [radius=0.6];
\draw [thick] (-0.9,-1.6) circle [radius=0.6];
\draw [thick] (1.7,-1.6) circle [radius=0.6];
\draw [thick] (6.8,-1.6) circle [radius=0.6];
\draw [thick] (9.4,-1.6) circle [radius=0.6];
%label state
\node (A) at (-3.5,-1.6) {1};
\node (B) at (-0.9,-1.6) {2};
\node (C) at (1.7,-1.6) {3};
\node (D) at (6.8,-1.6) {$m$};
\node (E) at (9.4,-1.6) {$m+1$};
%horizontal arrow
\draw [->, thick] (-2.9,-1.6) --(-1.5,-1.6);
\draw [->, thick] (-0.3,-1.6) --(1.1,-1.6);
\draw [->, thick] (2.3,-1.6) --(3.7,-1.6);
\draw [->, thick] (4.8,-1.6) --(6.2,-1.6);
\draw [->, thick] (7.4,-1.6) --(8.8,-1.6);
%dots
\draw [thick, dotted] (3.7,-1.6) -- (4.8,-1.6);
%parameters - horizontal arrow
\node [above] at (-2.2,-1.6) {{\footnotesize $x^{(m)}$}};
\node [above] at (0.4,-1.6) {{\footnotesize $D^{(m)}$}};
\node [above] at (3,-1.6) {{\footnotesize $D^{(m-1)}$}};
\node [above] at (5.5,-1.6) {{\footnotesize $D^{(3)}$}};
\node [above] at (8.1,-1.6) {{\footnotesize $D^{(2)}$}};
%vertical arrow
\draw [->, thick] (-3.5,1) --(-3.5,-1);
%bending arrow
\draw[->, thick] (A) to [out=60,in=120, looseness=1]
(C);
\draw[->, thick] (A) to [out=60,in=120, looseness=1]
(D);
\draw[->, thick] (A) to [out=60,in=120, looseness=1]
(E);
\node [right] at (-3.5,0) {{\footnotesize $\displaystyle \pi_1$}};
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
答案1
这是因为你画的圆不是节点,所以 Ti钾Z 不知道它必须从边界开始箭头。你最好给你的节点一个最小尺寸和一个形状(这里是圆形),并告诉 Ti钾Z 来绘制它们。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}[mystate/.style={draw,circle,minimum size=1.2cm}]
%circle
%\draw [thick] (-3.5,-1.6) circle [radius=0.6];
%\draw [thick] (-0.9,-1.6) circle [radius=0.6];
%\draw [thick] (1.7,-1.6) circle [radius=0.6];
%\draw [thick] (6.8,-1.6) circle [radius=0.6];
%\draw [thick] (9.4,-1.6) circle [radius=0.6];
%label state
\node[mystate] (A) at (-3.5,-1.6) {1};
\node[mystate] (B) at (-0.9,-1.6) {2};
\node[mystate] (C) at (1.7,-1.6) {3};
\node[minimum size=1.2cm] (C')at (4.25,-1.6){};
\node[mystate] (D) at (6.8,-1.6) {$m$};
\node[mystate] (E) at (9.4,-1.6) {$m+1$};
%horizontal arrow
\draw [->, thick] (A) -- (B) node[midway, above] {\footnotesize $x^{(m)}$};
\draw [->, thick] (B) -- (C) node[midway, above] {\footnotesize $D^{(m)}$};
\draw [->, thick] (C) -- (C') node[midway, above] {\footnotesize $D^{(m-1)}$};
\draw [->, thick] (C') -- (D) node[midway, above] {\footnotesize $D^{(3)}$};
\draw [->, thick] (D) -- (E) node[midway, above] {\footnotesize $D^{(2)}$};
%dots
\draw [thick, dotted] (3.7,-1.6) -- (4.8,-1.6);
%vertical arrow
\draw [->, thick] (-3.5,1) --(-3.5,-1);
%bending arrow
\draw[->, thick] (A) to [out=60,in=120, looseness=1]
(C);
\draw[->, thick] (A) to [out=60,in=120, looseness=1]
(D);
\draw[->, thick] (A) to [out=60,in=120, looseness=1]
(E);
\node [right] at (-3.5,0) {{\footnotesize $\displaystyle \pi_1$}};
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
现在,说实话,这不是绘制这种图形的最佳方法。你应该学习 hox 的使用chains
,并绘制edges
,也许使用quotes
库。我没有对你的代码进行太多修改,因为你不熟悉 Ti钾Z,但你会在这个网站上找到许多马尔可夫链的很好的例子。
答案2
这里有一个建议给你。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\def\a{2.5}
\path[nodes={circle,draw,minimum size=12mm}]
(0,0) node (1) {$1$}
++(\a,0) node (2) {$2$}
++(\a,0) node (3) {$3$}
;
\draw[<-] (1)--+(90:2) node[midway,right]{$\pi_1$};
\draw[->] (1)--(2) node[midway,above]{$x^{(m)}$};
\draw[->] (2)--(3) node[midway,above]{$D^{(m)}$};
\draw[->] (1) to[out=60,in=120] (3);
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}