所以我想画一个看起来像可视化编程中的组件 - 有输入和输出。我想把它放在一个盒子里。所以我试着把它放进一个盒子里,但它有点不对劲
以下是最小代码示例(重点关注最后三行):
\documentclass{article}
\usepackage{dot2texi}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,petri,positioning, fit}
\begin{document}
\tikzset{
place/.style={
circle,
thick,
draw=blue!75,
fill=blue!20,
minimum size=6mm,
},
transitionH/.style={
rectangle,
thick,
fill=black,
minimum width=8mm,
inner ysep=2pt
},
transitionV/.style={
rectangle,
thick,
fill=black,
minimum height=8mm,
inner xsep=2pt
}
}
\begin{tikzpicture}[>=latex',scale=0.8]
\begin{dot2tex}[dot,tikz,codeonly,styleonly,options=-s -tmath]
digraph MyGraph {
rankdir=LR;
subgraph cluster_4386357488 {
label = " <<GrowLamp>>"
{rank=source;
in_1 [ label="", style="place" ]
in_2 [ label="", style="place" ]
in_3 [ label="", style="place" ]
}
{
middle_1 [label="", style="transitionV"]
middle_2 [label="", style="place"]
}
{rank=sink;
out_1 [label="", style="transitionV"]
out_2 [label="", style="transitionV"]
}
in_1 -> middle_1;
in_2 -> middle_1;
in_3 -> middle_1;
middle_1->middle_2;
middle_2->out_1;
middle_2->out_2;
}
}
\end{dot2tex}
\node[draw,dotted,fit=(in_1.north) (in_3.south) (out_1.north) (out_2.south)] {};
\end{tikzpicture}
\end{document}
虚线框稍微偏离。如何让它穿过所有输入\输出节点中心?
答案1
像这样 ?
\documentclass{article}
\usepackage{dot2texi}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,petri,positioning, fit}
\begin{document}
\tikzset{
place/.style={
circle,
thick,
draw=blue!75,
fill=blue!20,
minimum size=6mm,
},
transitionH/.style={
rectangle,
thick,
fill=black,
minimum width=8mm,
inner ysep=2pt
},
transitionV/.style={
rectangle,
thick,
fill=black,
minimum height=8mm,
inner xsep=2pt
}
}
\begin{tikzpicture}[>=latex',scale=0.8]
\begin{dot2tex}[dot,tikz,codeonly,styleonly,options=-s -tmath]
digraph MyGraph {
rankdir=LR;
subgraph cluster_4386357488 {
label = " <<GrowLamp>>"
{rank=source;
in_1 [ label="", style="place" ]
in_2 [ label="", style="place" ]
in_3 [ label="", style="place" ]
}
{
middle_1 [label="", style="transitionV"]
middle_2 [label="", style="place"]
}
{rank=sink;
out_1 [label="", style="transitionV"]
out_2 [label="", style="transitionV"]
}
in_1 -> middle_1;
in_2 -> middle_1;
in_3 -> middle_1;
middle_1->middle_2;
middle_2->out_1;
middle_2->out_2;
}
}
\end{dot2tex}
%\node[draw,dotted,fit=(in_1.center) (in_3.center) (middle_2.center)] {};
\draw[red,dotted,thick] ([yshift=2mm]in_1.north) --([yshift=-2mm]in_3.south)-| (out_1.center)|-cycle;
\end{tikzpicture}
\end{document}