
我想繪製這個圖,這是我的程式碼和結果。我希望塊的大小及其距離與原始圖形相同。另外「網路」應該在虛線內
\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}