答案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
標籤作為練習。