我想绘制这个图形,这是我的代码和结果。我希望块的大小和距离与原始图形相同。此外,“网络”应该在虚线内
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,fit}
\usetikzlibrary{arrows,calc,positioning}
\usetikzlibrary{shapes,arrows,positioning,calc}
\begin{document}
\newlength\estilength
\settowidth\estilength{$estimator$}
\tikzset{
block/.style = {draw, fill=white, rectangle, minimum height=3em, minimum width=3em,text width=\estilength,align=center},
tmp/.style = {coordinate},
sum/.style= {draw, fill=white, circle, node distance=1cm},
input/.style = {coordinate},
output/.style= {coordinate},
pinstyle/.style = {pin edge={to-,thin,black}
},
point/.style = {draw, fill=black, circle, minimum size=0.8mm, node distance=1.5cm, inner sep=0pt},
dashed node/.style={draw,dashed,inner sep=7.5pt,rounded corners},
}%
\begin{tikzpicture}[auto, node distance=15mm,>=latex']
\node [block] (act) {$Actuator$};
\node [block, right=2 of act ] (plant) {Plant};
\node [block, right= 2 of plant] (c) {$sensor$};
\node [block, below=15mm of c] (delay) {$Delay$};
\node [block, below=30mmof plant] (control) {$controller$};
\node [block, below=15mm of act] (me) {$measur$};
\draw [->] (act) --(plant);
\draw [->] (plant) -- (c);
\draw [->] (c) -- (delay);
\draw [->] (delay) |- (control);
\draw [->] (control) -| (me);
\draw [->] (me) -- (act);
\node [dashed node,fit=(me)(delay),label=above:{network}] {};
\end{tikzpicture}
\end{document}
答案1
像这样?
该标签网络将真正位于节点的中心,您应该将其写为标签(参见下面的 MWE)。
在 MWE 中,我缩短了节点名称,添加了chains
库并\tikzset{...}
仅考虑图像中使用的样式:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
fit}
\begin{document}
\newlength\estilength
\settowidth\estilength{\emph{controller}}
\tikzset{
arr/.style = {-Latex, semithick},
every edge/.append style = {draw, arr},
FIT/.style args = {#1/#2}{draw, densely dashed, inner sep=1em,
label = {[font=\large]center:#1},
fit=#2,
},
N/.style = {draw, fill=white, align=center, font=\itshape,
minimum height=5ex, minimum width=\estilength,
text width=\pgfkeysvalueof{/pgf/minimum width}+2*\pgfkeysvalueof{/pgf/inner xsep},
},
P/.style = {N, font=\textrm\large, on chain},
}
\begin{tikzpicture}[auto,
node distance = 10mm and 15mm,
start chain = going right]
\begin{scope}[nodes={N, on chain, join=by arr}]
\node (act) {Actuator};
\node (plant) [P] {Plant};
\node (c) {sensor};
\end{scope}
\node (delay) [N, below=of c] {Delay};
\node (msr) [N, below=of act] {measure};
\node (cntrl) [N, below = of msr.south -| plant] {controller};
%
\node [FIT= network/(msr)(delay)] {};
%
\draw[arr] (msr) edge (act)
(c) to (delay);
\draw [arr] (delay) |- (cntrl);
\draw [arr] (cntrl) -| (msr);
\end{tikzpicture}
\end{document}
附录:
显然我错过了第一张图片,并要求 MWE 重现它。下面的新 MWE 可以实现这一点:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
fit}
\begin{document}
\newlength\estilength
\settowidth\estilength{\emph{controller}}
\tikzset{
arr/.style = {-Latex, semithick},
every edge/.append style = {draw, arr},
FIT/.style args = {#1/#2}{draw, densely dashed, inner sep=1em,
label = {[font=\large]center:#1},
fit=#2,
},
N/.style = {draw, semithick, align=center, font=\itshape,
minimum height=5ex, minimum width=#1,
text width=\pgfkeysvalueof{/pgf/minimum width}+2*\pgfkeysvalueof{/pgf/inner xsep},
},
N/.default = \estilength,
P/.style = {N, font=\textrm\large, on chain},
}
\begin{tikzpicture}[auto,
node distance = 10mm and 15mm,
start chain = going right]
\begin{scope}[nodes={N, on chain, join=by arr}]
\node (act) {Actuator};
\node (plant) [P] {Plant};
\node (c) {sensor};
\end{scope}
\node (delay) [N=2*\estilength, below=of c] {Actuation\\ Delay}; % here is adjusted width of node's shape
\node (msr) [N=2*\estilength, below=of act] {Measurement\\ Delay}; % here is adjusted width of node's shape
\node (cntrl) [N, below = of msr.south -| plant] {controller};
%
\node [FIT= network/(msr)(delay)] {};
%
\draw[arr] (msr) edge (act)
(c) to (delay);
\draw [arr] (delay) |- (cntrl);
\draw [arr] (cntrl) -| (msr);
\end{tikzpicture}
\end{document}