我想要类似下图的东西:
但我得到的是:
这是我的代码:
\begin{center}
\begin{tikzpicture}[node distance=1.5cm]
% position the nodes a..d
\node (a) [] {$\textrm{I}$};
\node (b) [right of=a] {};
\node (c) [right of=b] {};
\node (d) [right of=c] {};
\node (e) [right of=d] {};
\node (f) [right of=e] {};
\node (g) [right of=f] {};
\node (h) [right of=g] {};
\node (i) [right of=h] {};
\node (j) [right of=i] {};
\node (k) [right of=j] {};
\node (l) [right of=k] {};
% draw the bullets/circles at the above defined positions
\filldraw (b) circle (1.5pt);
\filldraw (c) circle (1.5pt);
\filldraw (d) circle (1.5pt);
\filldraw (e) circle (1.5pt);
\filldraw (f) circle (1.5pt);
\draw (f) circle (5pt);
\filldraw (g) circle (1.5pt);
\filldraw (h) circle (1.5pt);
\filldraw (i) circle (1.5pt);
\filldraw (j) circle (1.5pt);
\filldraw (k) circle (1.5pt);
\filldraw (l) circle (1.5pt);
\draw (l) circle (5pt);
% draw arrows/connections, use 'shorten' to finetune space
\path[draw, ->, shorten >=3pt, shorten <=-2pt] (a) -- (b) ;
\draw[->, shorten >=1pt, shorten <=3pt] (b) -- (c)
node [above=0pt, pos=0.5, font=\footnotesize]{$\varepsilon$};
\draw[->, shorten >=1pt, shorten <=3pt] (c) -- (d)
node [above=0pt, pos=0.5, font=\footnotesize]{$1$};
\draw[->, shorten >=1pt, shorten <=3pt] (d) -- (e)
node [above=0pt, pos=0.5, font=\footnotesize]{$\varepsilon$};
\draw[->, shorten >=1pt, shorten <=3pt] (e) -- (f)
node [above=0pt, pos=0.5, font=\footnotesize]{$0$};
\path[->, shorten >=3pt, shorten <=1pt, bend left]
(b) edge node [above=0., pos=0.5, font=\footnotesize]{$\varepsilon$} (g) ;
\draw[->, shorten >=1pt, shorten <=3pt] (g) -- (h)
node [above=0pt, pos=0.5, font=\footnotesize]{$0$};
\draw[->, shorten >=1pt, shorten <=3pt] (h) -- (i)
node [above=0pt, pos=0.5, font=\footnotesize]{$\varepsilon$};
\draw[->, shorten >=1pt, shorten <=3pt] (i) -- (j)
node [above=0pt, pos=0.5, font=\footnotesize]{$0$};
\draw[->, shorten >=1pt, shorten <=3pt] (j) -- (k)
node [above=0pt, pos=0.5, font=\footnotesize]{$\varepsilon$};
\draw[->, shorten >=1pt, shorten <=3pt] (k) -- (l)
node [above=0pt, pos=0.5, font=\footnotesize]{$1$};
\end{tikzpicture}
\end{center}
有人知道如何使图表看起来像第一个图(照片)吗?
答案1
您可以使用below right
等above right
来定位相对于当前节点的这些方向的节点。它需要positioning
库来访问额外的选项。
此外,您可以添加一些自定义样式以避免重复。
这个例子
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}[
node distance=1.5cm,
every node/.style={draw, fill, circle, inner sep=1.5pt},
endnode/.style={fill=none, inner sep=5pt},
every edge/.style={draw, ->, shorten >=5pt, shorten <=5pt},
itslabel/.style={draw=none, fill=none, above=0pt, pos=0.5},
]
% position the nodes a..d
\node (a) [draw=none,fill=none, font=\large] {I};
\node (b) [right=of a] {};
\node (c) [above right=of b] {};
\node (d) [right=of c] {};
\node (e) [right=of d] {};
\node (f) [right=of e] {};
\node (fend) [endnode] at (f) {};
\node (g) [below right=of b] {};
\node (h) [right=of g] {};
\node (i) [right=of h] {};
\node (j) [right=of i] {};
\node (k) [right=of j] {};
\node (l) [right=of k] {};
\node (lend) [endnode] at (l) {};
\path (a.center) edge (b)
(b) edge node [itslabel, pos=0.38, above=5pt] {\(\varepsilon\)} (c)
(c) edge node [itslabel] {\(1\)} (d)
(d) edge node [itslabel] {\(\varepsilon\)} (e)
(e) edge [shorten >=1em] node [itslabel] {0} (f)
(b) edge node [itslabel, pos=0.32, below=5pt] {\(\varepsilon\)} (g)
(g) edge node [itslabel] {\(0\)} (h)
(h) edge node [itslabel] {\(\varepsilon\)} (i)
(i) edge node [itslabel] {\(0\)} (j)
(j) edge node [itslabel] {\(\varepsilon\)} (k)
(k) edge [shorten >=1em] node [itslabel] {\(1\)} (l);
\end{tikzpicture}
\end{center}
\end{document}