我写了以下代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,decorations.pathmorphing,backgrounds,positioning,fit,petri}
\begin{document}
\begin{tikzpicture}
[place/.style={circle,draw,thick,inner sep=0pt,minimum size=6mm},transition/.style={rectangle,draw,thick,inner sep=0pt,minimum size=4mm}]
\node[place] (c1) at (-3,6) {};
\node[place] (c2) at (0,6) {};
\node[place] (c3) at (0,3) {};
\node[place] (c4) at (1.5,2) {};
\node[place] (c5) at (-1.5,2) {};
\node[place] (c6) at (0,0) {};
\node[place] (c7) at (-3,1) {};
\node[place] (c8) at (2,1) {};
\node[place] (c9) at (-2,0) {};
\node[place] (c10) at (-2,-4) {};
\node[place] (c11) at (-2,-8) {};
\node[place] (c12) at (2,-4) {};
\node[place] (c13) at (2,-8) {};
\node[transition] (r1) at (-1,1) {};
\node[transition] (r2) at (1,1) {};
\node[transition] (r3) at (1,4.5) {};
\node[transition] (r4) at (-1,4.5) {};
\node[transition] (r5) at (-3,4.5) {};
\node[transition] (r6) at (-3,2) {};
\node[transition] (r7) at (-1,-2) {};
\node[transition] (r8) at (-2,-6) {};
\node[transition] (r9) at (1,-2) {};
\node[transition] (r10) at (2,-6) {};
\draw [->,thick] (c11) to (r8);
\draw [->,thick] (c10) to (r8);
\draw [->,thick] (c12) to (r10);
\draw [->,thick] (c13) to (r10);
\draw [->,thick] (r8) to [bend right=45] (c10);
\draw [->,thick] (r10) to [bend left=45] (c12);
\draw [->,thick] (r7) to (c10);
\draw [->,thick] (r9) to (c12);
\draw [->,thick] (c6) to (r7);
\draw [->,thick] (c6) to (r9);
\draw [->,thick] (c1) to (r5);
\draw [->,thick] (r5) to (c3);
\draw [->,thick] (r4) to (c3);
\draw [->,thick] (c3) to (r3);
\draw [->,thick] (r3) to (c2);
\draw [->,thick] (c2) to (r4);
\draw [->,thick] (c3) to (r1);
\draw [->,thick] (c3) to (r2);
\draw [->,thick] (r1) to (c6);
\draw [->,thick] (r2) to (c6);
\draw [->,thick] (c9) to [bend right=45] (r7);
\draw [->,thick] (r7) to [bend right=45] (c9);
\draw [->,thick] (c7) to (r6);
\draw [->,thick] (r6) to [bend right=45] (c5);
\draw [->,thick] (c5) to [bend right=45] (r6);
\draw [->,thick] (c7) to [bend right=45] (r1);
\draw [->,thick] (r1) to [bend right=45] (c7);
\draw [->,thick] (r2) to [bend right=45] (c8);
\draw [->,thick] (c8) to [bend right=45] (r2);
\draw [->,thick] (c4) to [bend right=45] (r2);
\draw [->,thick] (r2) to [bend right=45] (c4);
\draw [->,thick] (r1) to (c5);
\end{tikzpicture}
\end{document}
结果是:
我怎样才能通过这种方式改进它:
为了使圆圈的颜色和大小、箭头的尖端以及矩形的形状和颜色如下图所示(我不需要所有矩形都是垂直的,有些是垂直的,有些是水平的):
答案1
我做了一些调整来回答你的问题。当然,你稍后应该再次微调定位。
改编
- 删除选项前的空行
tikzpicture
- 添加
, minimum size=9mm, draw=blue!50, fill=blue!20
place/.style
- 定义
transitionh
(水平)和transitionv
(垂直)minimum width
并minimum height
设置 - 改变箭头尖
>=latex
- 删除了未使用的 tikzlibraries:
decorations.pathmorphing,backgrounds,fit
- 您可以插入多个令牌,使用
tokens=1
等等。
建议
- 我离开
positioning
那里,因为我建议使用它进行相对定位而不是绝对定位。 - 看看pgf/tikz 手册第 64 章“Petri-Net 绘图库”(有一些很好的例子)。
结果
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning,petri}
\begin{document}
\begin{tikzpicture}[
place/.style={circle, draw, thick, inner sep=0pt, minimum size=9mm, draw=blue!50, fill=blue!20},
transition/.style={rectangle, draw, thick, inner sep=0pt, minimum size=4mm, fill=black},
transitionh/.style={transition, minimum width=8mm, minimum height=3mm},
transitionv/.style={transition, minimum height=8mm, minimum width=3mm},
>=latex,
]
\node[place, tokens=1] (c1) at (-3,6) {};
\node[place, tokens=2] (c2) at (0,6) {};
\node[place] (c3) at (0,3) {};
\node[place] (c4) at (1.5,2) {};
\node[place] (c5) at (-1.5,2) {};
\node[place] (c6) at (0,0) {};
\node[place] (c7) at (-3,1) {};
\node[place] (c8) at (2,1) {};
\node[place] (c9) at (-2,0) {};
\node[place] (c10) at (-2,-4) {};
\node[place] (c11) at (-2,-8) {};
\node[place] (c12) at (2,-4) {};
\node[place] (c13) at (2,-8) {};
\node[transitionh] (r1) at (-1,1) {};
\node[transitionh] (r2) at (1,1) {};
\node[transitionh] (r3) at (1,4.5) {};
\node[transitionh] (r4) at (-1,4.5) {};
\node[transitionh] (r5) at (-3,4.5) {};
\node[transitionv] (r6) at (-3,2) {};
\node[transitionh] (r7) at (-1,-2) {};
\node[transitionh] (r8) at (-2,-6) {};
\node[transitionh] (r9) at (1,-2) {};
\node[transitionh] (r10) at (2,-6) {};
\draw [->,thick] (c11) to (r8);
\draw [->,thick] (c10) to (r8);
\draw [->,thick] (c12) to (r10);
\draw [->,thick] (c13) to (r10);
\draw [->,thick] (r8) to [bend right=45] (c10);
\draw [->,thick] (r10) to [bend left=45] (c12);
\draw [->,thick] (r7) to (c10);
\draw [->,thick] (r9) to (c12);
\draw [->,thick] (c6) to (r7);
\draw [->,thick] (c6) to (r9);
\draw [->,thick] (c1) to (r5);
\draw [->,thick] (r5) to (c3);
\draw [->,thick] (r4) to (c3);
\draw [->,thick] (c3) to (r3);
\draw [->,thick] (r3) to (c2);
\draw [->,thick] (c2) to (r4);
\draw [->,thick] (c3) to (r1);
\draw [->,thick] (c3) to (r2);
\draw [->,thick] (r1) to (c6);
\draw [->,thick] (r2) to (c6);
\draw [->,thick] (c9) to [bend right=45] (r7);
\draw [->,thick] (r7) to [bend right=45] (c9);
\draw [->,thick] (c7) to (r6);
\draw [->,thick] (r6) to [bend right=45] (c5);
\draw [->,thick] (c5) to [bend right=45] (r6);
\draw [->,thick] (c7) to [bend right=45] (r1);
\draw [->,thick] (r1) to [bend right=45] (c7);
\draw [->,thick] (r2) to [bend right=45] (c8);
\draw [->,thick] (c8) to [bend right=45] (r2);
\draw [->,thick] (c4) to [bend right=45] (r2);
\draw [->,thick] (r2) to [bend right=45] (c4);
\draw [->,thick] (r1) to (c5);
\end{tikzpicture}
\end{document}