答案1
TikZ
一开始可能会令人生畏,但值得学习。掌握基础知识后,有更有效的方法来绘制图表,但首先,请专注于几个基本命令:\draw
和\node
。这应该可以帮助您入门:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes} % allows ellipse nodes
\tikzset{ellnode/.style={draw, ellipse, inner sep=.5mm}} % define the style you'll use later
\begin{document}
\begin{tikzpicture}[xscale=1.5] % stretch coordinates in the x-direction. Doesn't affect text.
% draw axis
\draw[thick, ->](-4,0)--(0,0)node[above]{$t$};
% draw tick marks
\draw (-1,.2)--(-1,-.2)node[below]{$-1$};
% draw nodes
\node[ellnode] at (0,1)(n01){$s_3$}; % ellnode is the style you defined earlier
\node[ellnode] at (0,2)(n02){$s_2$}; % n02 is the name of this node for later use
\node[ellnode] at (0,3)(n03){$s_1$};
\node[ellnode] at (-1,1)(n11){$s_3$};
\node[ellnode] at (-1,2)(n12){$s_2$};
\node[ellnode] at (-1,3)(n13){$s_1$};
% draw lines
\draw[->, dashed](n11)--(n03); % draw lines using the node names from above
\draw[->, dashed](n12)--(n03);
\draw[->](n13)--(n02);
\end{tikzpicture}
\end{document}
答案2
作为起点。使用循环来定位节点组。节点组的数量由循环的重复次数定义。
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
shapes}
\begin{document}
\begin{tikzpicture}[
> = Straight Barb,% on grid,
node distance = 7mm and 20mm,
C/.style = {ellipse, draw, minimum width =1.2em, inner sep=1pt},
every edge/.style = {draw, ->}
]
\foreach \x[count=\i] in {0,-1,-2}
{
\node (n\x1) [C] at (2*\x,0) {$s_1$};
\node (n\x2) [C,below=of n\x1] {$s_2$};
\node (n\x3) [C,below=of n\x2] {$s_3$};
}
\coordinate[below right=7mm and 7mm of n03.south] (R);
\draw[<-, shorten > = -3mm] (R) node[right] {$t$} -- ++ (-8.4,0);
\foreach \x in {0,-1,...,-4}
\draw (R) ++ (2*\x-0.7,1mm) -- ++ (0,-2mm) node[below] {$\x$};
%
\draw (n-21) edge[dashed] (n-12)
(n-22) edge (n-11)
(n-23) edge (n-11)
(n-11) edge (n02)
(n-12) edge[dashed] (n01)
(n-13) edge[dashed] (n01);
\end{tikzpicture}
\end{document}