![TikZ:在控制系统图的 tikz 图片中创建边界框](https://linux22.com/image/478154/TikZ%EF%BC%9A%E5%9C%A8%E6%8E%A7%E5%88%B6%E7%B3%BB%E7%BB%9F%E5%9B%BE%E7%9A%84%20tikz%20%E5%9B%BE%E7%89%87%E4%B8%AD%E5%88%9B%E5%BB%BA%E8%BE%B9%E7%95%8C%E6%A1%86.png)
我已经在 TikZ 中完成了控制系统的编写。现在我想创建两个带有虚线的彩色“框”,它们应该包含整个控制回路的控制器和工厂组件。请参考最后的图来了解我的意思。
我如何在 TikZ 中做到这一点?这些框需要与图片中的样子完全一样,并且还要有一个如图所示的标题。
另外:如何在图中所示的线条上添加描述?
谢谢你!
我的代码在这里:
\documentclass[a4paper,12pt]{article}
\usepackage{graphicx} % Um Grafiken (bspw. das Logo) einbinden zu können
\usepackage{pgf, tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{shapes}
\usepgflibrary{arrows.meta}
\tikzstyle{block} = [draw, fill=blue!10, rectangle,
minimum height=2em, minimum width=5em]
\tikzstyle{sum} = [draw, fill=blue!20, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={Triangle[],thick,black}]
\tikzstyle{arrow} = [draw,thick,-{Triangle[]}]
\tikzstyle{line} = [draw,thick,-]
\tikzstyle{triangle} = [draw,fill=red!20,regular polygon,regular polygon sides=3]
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[auto,node distance=2cm,scale=1.0]
\node [input](input){};
\node [sum, right of=input, node distance=2cm](sum1){};
\node [block, fill=cyan!20, right of=sum1, node distance=3cm](fbcont){Feedback};
\node [sum, right of=fbcont, node distance=2cm](sum2){};
\node [block, fill=pink!20, right of=sum2, node distance=3cm](act){Actuator};
\node [block, fill=orange!20, right of=act, node distance=3.5cm](plant){Plant};
\node [block, fill=green!20, above of=fbcont](ffcont){Feed-forward};
\node [block, fill=brown!20, below of=act](sens1){Sensor};
\node [input, below of=sum1](interim){};
\node [output, right of=plant](out1){};
\node [output, below of=out1](out2){};
\draw [arrow] (sum1)--node{$e(t)$}(fbcont);
\draw [arrow] (fbcont)--(sum2);
\draw [arrow] (sum2)--node{$u(t)$}(act);
\draw [arrow] (act)--(plant);
\draw [line] (plant)--(out1);
\draw [arrow] (out1)|-(sens1);
\draw [arrow] (sens1)-|node[pos=0.99]{$-$} node [near end]{$y_m(t)$} (sum1);
\draw [line] (interim)-|(input);
\draw [arrow] (input)--node{$r(t)$}(sum1);
\draw [arrow] (input)|-(ffcont);
\draw [arrow] (ffcont)-|(sum2);
\end{tikzpicture}
\end{figure}
\end{document}
答案1
这是 fit 库的任务,它允许您调整某些节点。您可以使用 来inner sep
缩小或扩大边距。请注意,\tikzstyle
已弃用。
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,fit}
\tikzset{block/.style={draw, fill=blue!10, rectangle,
minimum height=2em, minimum width=5em},
sum/.style={draw, fill=blue!20, circle, node distance=1cm},
input/.style={coordinate},
output/.style={coordinate},
pinstyle/.style={pin edge={Triangle[],thick,black}},
arrow/.style={draw,thick,-{Triangle[]}},
line/.style={draw,thick,-},
triangle/.style={draw,fill=red!20,regular polygon,regular polygon sides=3}}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[auto,node distance=2cm,scale=1.0]
\node [input](input){};
\node [sum, right of=input, node distance=2cm](sum1){};
\node [block, fill=cyan!20, right of=sum1, node distance=3cm](fbcont){Feedback};
\node [sum, right of=fbcont, node distance=2cm](sum2){};
\node [block, fill=pink!20, right of=sum2, node distance=3cm](act){Actuator};
\node [block, fill=orange!20, right of=act, node distance=3.5cm](plant){Plant};
\node [block, fill=green!20, above of=fbcont](ffcont){Feed-forward};
\node [block, fill=brown!20, below of=act](sens1){Sensor};
\node [input, below of=sum1](interim){};
\node [output, right of=plant](out1){};
\node [output, below of=out1](out2){};
\draw [arrow] (sum1)--node{$e(t)$}(fbcont);
\draw [arrow] (fbcont)--(sum2);
\draw [arrow] (sum2)--node{$u(t)$}(act);
\draw [arrow] (act)--(plant);
\draw [line] (plant)--(out1);
\draw [arrow] (out1)|-(sens1);
\draw [arrow] (sens1)-|node[pos=0.99]{$-$} node [near end]{$y_m(t)$} (sum1);
\draw [line] (interim)-|(input);
\draw [arrow] (input)--node{$r(t)$}(sum1);
\draw [arrow] (input)|-(ffcont);
\draw [arrow] (ffcont)-|(sum2);
\node[fit=(sum1|-sens1)(ffcont)(sum2)(input),draw,blue,dashed,
label={[blue]above:Controller}]{};
\node[fit=(sens1)(plant),draw,orange,dashed,
label={[orange]above:Controller}]{};
\end{tikzpicture}
\end{figure}
\end{document}