我正在尝试使用 TikZ 绘制以下流。 这里的问题是最底下的那条线。我不知道如何在 TikZ 中绘制那一行。
以下是我尝试过的以及它的外观:
\begin{tikzpicture}[auto, node distance=1.2cm, align=center]
\node[state, line width=0.01mm, fill=examplecolor!20, text width=4mm] (q0) {\large{\textbf{2}}};
\node[state, right=of q0, line width=0.01mm, fill=examplecolor!20, text width=4mm] (q1) {\large{\textbf{1}}};
\node[state, right=of q1, line width=0.01mm, fill=examplecolor!20, text width=4mm] (q2) {\large{\textbf{3}}};
\node[left=of q0] (off0) {$x$};
\node[right=of q2] (off1) {};
\node[state, below=of q0, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm] (r0) {\large{\textbf{0}}};
\node[state, right=of r0, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm] (r1) {\large{\textbf{2}}};
\node[state, right=of r1, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm] (r2) {\large{\textbf{3}}};
\node[left=of r0] (off2) {last$(s,x)$};
\node[right=of r2] (off3) {};
\node[signal, below=of r0, signal to=east, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm] (s0) {\large{\textbf{0}}};
\node[signal, right=of s0, signal to=east, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm] (s1) {\large{\textbf{2}}};
\node[signal, right=of s1, signal to=east, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm] (s2) {\large{\textbf{3}}};
\node[left=of s0] (off4) {$s$};
\path[-, line width=0.01mm]
(q0) edge node {} (q1)
(q1) edge node {} (q2)
(r0) edge node {} (r1)
(r1) edge node {} (r2);
\path[->, line width=0.01mm]
(q2) edge node {} (off1)
(r2) edge node {} (off3);
\path[|-, line width=0.01mm]
(off0) edge node {} (q0)
(off2) edge node {} (r0);
\end{tikzpicture}
此代码产生以下结果:
现在,似乎“信号”不是我目前正在寻找的东西,但我找不到其他任何东西来完成这项任务。有人知道如何在 TikZ 中绘制最后一行吗?
感谢您的帮助!
答案1
您可以使用calc
库来计算minimum width
节点signal
。
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning, automata,shapes.symbols,calc}
\colorlet{examplecolor}{cyan}
\colorlet{forestgreen(web)}{green}
\begin{document}
\begin{tikzpicture}[auto, node distance=1.2cm, align=center]
\node[state, line width=0.01mm, fill=examplecolor!20, text width=4mm] (q0) {\large{\textbf{2}}};
\node[state, right=of q0, line width=0.01mm, fill=examplecolor!20, text width=4mm] (q1) {\large{\textbf{1}}};
\node[state, right=of q1, line width=0.01mm, fill=examplecolor!20, text width=4mm] (q2) {\large{\textbf{3}}};
\node[left=of q0] (off0) {$x$};
\node[right=of q2] (off1) {};
\node[state, below=of q0, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm] (r0) {\large{\textbf{0}}};
\node[state, right=of r0, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm] (r1) {\large{\textbf{2}}};
\node[state, right=of r1, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm] (r2) {\large{\textbf{3}}};
\node[left=of r0] (off2) {last$(s,x)$};
\node[right=of r2] (off3) {};
\path let \p1=($(r0.center)-(off2.east)$), \n2={veclen(\x1,\y1)} in node[draw, signal, below left= 1.2cm and 0pt of r0.center, signal to=east, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm, anchor=east, minimum width=\n2] (s0) {\large{\textbf{0}}};
\path let \p1=($(r1.center)-(r0.center)$), \n2={veclen(\x1,\y1)} in node[draw, signal, right= 0pt of s0.east, anchor=west, signal to=east and west, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm, minimum width=\n2] (s1) {\large{\textbf{2}}};
\path let \p1=($(r2.center)-(r1.center)$), \n2={veclen(\x1,\y1)} in node[draw, signal, right=0pt of s1.east, anchor=west, signal to=east and west, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm, minimum width=\n2] (s2) {\large{\textbf{3}}};
\path let \p1=($(off3.center)-(r2.center)$), \n2={veclen(\x1,\y1)} in node[draw, signal, right=0pt of s2.east, anchor=west, signal to=west, line width=0.01mm, fill=forestgreen(web)!20, text width=4mm, minimum width=\n2] (s2) {\large{\textbf{6}}};
\node[anchor=east] at (off2.east|-s1) {$s$};
\path[-, line width=0.01mm]
(q0) edge node {} (q1)
(q1) edge node {} (q2)
(r0) edge node {} (r1)
(r1) edge node {} (r2);
\path[->, line width=0.01mm]
(q2) edge node {} (off1)
(r2) edge node {} (off3);
\path[|-, line width=0.01mm]
(off0) edge node {} (q0)
(off2) edge node {} (r0);
\end{tikzpicture}\end{document}