正如您在我这个最小示例中看到的,我有一个状态机图,学生可以在文本框中写下转换线的名称。您能给我一些关于如何在等待状态中放置文本字段的建议吗?
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning, calc, shadings, shadows, shapes.arrows,fit, arrows.meta, matrix, mindmap}
\usepackage{tikz-uml}
\usepackage{hyperref}
\begin{document}
\begin{tikzpicture}[
transition textfield extension/.style n args = {4}{
color=black,
rounded corners,
arrows={-Straight Barb[angle=60:9pt 2]},
insert path={node[minimum size=12pt,yshift=0.5cm,xshift=#2] at ($(#3)!#1!(#4)$){\TextField[name=name,width=2cm,height=1em,multiline=false,bordercolor=black, charsize=9pt]{}}},
}]
\begin{umlstate}[name=Statemaschine]{Lightcontrol}
\umlstateinitial[name=start,x=0,y=3]{start}
\umlbasicstate [below left=5of start,fill=red!20, width=5cm] {waiting}
\umlHVtrans[transition textfield extension={.1}{-3cm}{start}{waiting}]{start}{waiting}
\end{umlstate}
\end{tikzpicture}
\end{document}
答案1
我不确定我是否理解正确,但是如果您想在状态节点内放置一个文本字段,只需在name
状态节点中添加一个常规,\node
然后将其放置在center
状态节点的锚点处即可。在我看来,这是最干净的解决方案。我真的不认为有必要使用类似insert path
这里的东西。
\documentclass[border=10pt]{standalone}
\usepackage{tikz-uml}
\usetikzlibrary{positioning, arrows.meta}
\usepackage{hyperref}
\begin{document}
\begin{tikzpicture}[
transition extension/.style={
arrows={-Straight Barb[angle=60:9pt 2]},
}]
\begin{umlstate}[name=Statemaschine]{Lightcontrol}
\umlstateinitial[name=start, x=0,y=3]{start}
\umlbasicstate[below left=5 of start, fill=red!20, width=5cm, name=waiting] {waiting}
\umlHVtrans[transition extension]{start}{waiting}
\end{umlstate}
\node[anchor=north] at (waiting.center) {\TextField[name=name, width=2cm, height=1em, multiline=false, bordercolor=black, charsize=9pt]{}};
\end{tikzpicture}
\end{document}