答案1
定义pics
如下第 18 章蒂克兹手动操作绝对是最佳选择。下面的代码定义了两个图片,2box
以及3box
分别包含两个或三个圆圈或正方形的框。2box
稍微简单一些,因为它只需要四个参数:两个圆圈中的标签以及箭头上方和下方的标签。使用这个,您可以使用以下方法绘制顶部框
\pic at (0,0) {2box={r,a,1{\mid}0,01}};
定义pic
了以下有用的节点:
ra
整个盒子ra-r
第一个圆圈ra-a
第二个圆圈
这部分是为了绘制图片,部分是为了稍后绘制箭头。3box
图片类似,但它需要七个参数:三个节点标签和两个箭头上方和下方的四个标签。
有了这些,接下来只需使用2box
和绘制框3box
,然后绘制边缘。起初,我考虑使用positioning
库来放置节点,但遗憾的是,pics
和positioning
不能很好地协同工作,所以我手动放置了所有内容以生成:
为了便于更改,我应用了大量样式。以下是完整代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\tikzset{
arrow/.style = {-{LaTeX}, thick},
label/.style = {pos=0.4, font=\scriptsize},
mynode/.style = {fill=white, inner sep=3pt, thick, draw=black},
onode/.style = {circle, mynode},
snode/.style = {rectangle, mynode},
box/.style = {thick, fill=gray!50, draw=black, anchor=south west},
pics/2box/.style args = {#1,#2,#3,#4}{% a,b,top,bot
code = {
\node[box, minimum width=2cm, minimum height=1cm](#1#2) at (0,0){};
\node[onode] (#1#2-#1) at (0.4,0.5){#1};
\node[onode] (#1#2-#2) at (1.6,0.5){#2};
\draw[arrow](#1#2-#1) -- node[label,above]{$#3$}
node[label,below]{$#4$} (#1#2-#2);
}
},
pics/3box/.style args = {#1,#2,#3,#4,#5,#6,#7}{% a,b,c,top,bot,top,bot}
code = {
\node[box, minimum width=2cm, minimum height=2cm](#1#2#3) at (0,0){};
\node[snode] (#1#2#2-#1) at (0.4,1.5){#1};
\node[snode] (#1#2#2-#2) at (0.4,0.5){#2};
\node[onode] (#1#2#2-#3) at (1.6,1){#3};
\draw[arrow](#1#2#2-#1.east) to[out=20, in=135]
node[label,above]{$#4$} node[label,below]{$#5$} (#1#2#2-#3);
\draw[arrow](#1#2#2-#2.east) to[out=-20, in=225]
node[label,above]{$#6$} node[label,below]{$#7$} (#1#2#2-#3);
}
},
}
\begin{document}
\begin{tikzpicture}
\pic at (0,9) {2box={r,a,1{\mid}0,01}};
\pic at (0,6) {3box={b,q,m,1{\mid}0,02,2{\mid}0,02}};
\pic at (1,4) {2box={q,b,1{\mid}0,03}};
\pic at (0,2) {2box={e,p,1{\mid}2,04}};
\pic at (0,0) {2box={q,e,1{\mid}0,05}};
\draw[arrow] (ra.south)--(bqm.north);
\draw[arrow] (bqm.south)--(qb.north);
\draw[arrow] (bqm) to[out=250, in=120](ep);
\draw[arrow] (ep.south)--(qe.north);
\draw[arrow] (qe.south)--++(0,-0.5);
\draw[thick](0.5,10.6) -- ++(0,-0.1)--++(1,0)--++(0,0.1);
\draw[{LaTeX}-,thick](ra.north)--++(0,0.5);
\draw[arrow,rounded corners]
(2.5,4)--++(0,-0.3)--++(1,0)--++(0,6.65)--++(-2,0)--++(0,-0.35);
\end{tikzpicture}
\end{document}
2box
正如你所见,和的定义3box
只是相当相似的小部分蒂克兹代码。里面用的是相对坐标的定义pics
。我把\delta
标签留作练习。