![记录内的自动机](https://linux22.com/image/252825/%E8%AE%B0%E5%BD%95%E5%86%85%E7%9A%84%E8%87%AA%E5%8A%A8%E6%9C%BA.png)
有人可以帮帮我吗?
我想定义一个带有参数(输入/输出变量和自动机)的新形状。
它看起来应该是这样的:
INPUT OUTPUT
+------+--------------------------------------+------+
| | | |
| v1 | | |
| | | |
+------+ AUTOMAT | o1 |
| | | |
| v2 | | |
| | | |
+------+--------------------------------------+------+
我没有足够的技能来定义如此复杂的对象。我很感激任何帮助。
答案1
你是指这样的吗?
该图片是通过以下方式实现的:
\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\newcounter{image}
\setcounter{image}{0}
\pgfmathtruncatemacro{\recordwidth}{4}
\pgfmathtruncatemacro{\recordheight}{2}
\newcommand{\setrecordwidth}[1]{\pgfmathtruncatemacro{\recordwidth}{#1}}
\newcommand{\setrecordheight}[1]{\pgfmathtruncatemacro{\recordheight}{#1}}
\tikzset{drawinside/.code n args={4}{%
\node at ($(#1.north west)!0.5!(#1.west)!0.15!(#1.center)$){#2};
\node at ($(#1.south west)!0.5!(#1.west)!0.15!(#1.center)$){#3};
\draw($(#1.north west)!0.30!(#1.north)$)--($(#1.south west)!0.30!(#1.south)$);
\draw(#1.west)--($(#1.west)!0.30!(#1.center)$);
\draw($(#1.north east)!0.30!(#1.north)$)--($(#1.south east)!0.30!(#1.south)$);
\node at ($(#1.east)!0.15!(#1.center)$) {#4};
}
}
\tikzset{record/.style args={#1 and #2}{
rectangle,draw,minimum width=#1, minimum height=#2
}
}
\NewDocumentCommand{\drawrecord}{d() m m m}{
\stepcounter{image}
\IfNoValueTF{#1}{%true
\node[record=\recordwidth cm and \recordheight cm,name=a\theimage]{};
}
{%false
\node[record=\recordwidth cm and \recordheight cm,name=a\theimage]at(#1){};
}
\node[drawinside={a\theimage}{#2}{#3}{#4}]{};
}
\begin{document}
\tikz{\drawrecord{$v_1$}{$v_2$}{$o_1$}}
\tikz{\drawrecord{$v_4$}{$v_5$}{$o_2$}}
\vspace*{2cm}
\begin{tikzpicture}
\drawrecord(0,0){$v_1$}{$v_2$}{$o_1$}
\setrecordwidth{6}
\setrecordheight{3}
\drawrecord(7,0){$v_1$}{$v_2$}{$o_1$}
\end{tikzpicture}
\end{document}
基本命令是\drawrecord
接受输入和输出变量作为参数,图片位置作为可选参数。可以通过专用命令\setrecordwidth
和自定义记录的宽度和高度\setrecordheight
。