这是我第一次在 Latex 上使用 Tikz。我必须绘制此框图(这是从一篇论文中截取的低分辨率图片)
这非常相似,但我需要一些调整,例如 u_i 箭头和 H(s) 块后的节点总和。
有人能帮我解决这个问题吗?我的代码:
\tikzstyle{block} = [draw, fill=white, rectangle,
minimum height=2em, minimum width=3em]
\tikzstyle{sum} = [draw, fill=white, circle, radius=1mm, node distance=1.5cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
\node [input, name=input] {};
\node [input, above of=input](input1) {};
\node [sum, right of=input] (sum) {};
\node [block, right of=sum] (controller) {$K(s)$};
\node [sum, right of=controller] (sum1) {};
\node [block, right of=sum1] (filterinv) {$H^{-1}(s)$};
\node [block, right of=filterinv] (system) {$G(s)$};
\node [output, right of=system] (output) {};
\node [output, above of=output] (output1) {};
\node [block, below of=filterinv] (filter) {$H(s)$};
\node [block, above of=controller] (delay) {$D(s)$};
\node [sum, below of=sum1] (sum2) {};
\draw [->] (filterinv) -- node[name=u] {$u_{i}$} (system);
\draw [draw,->] (input) -- node {$s_{i-1}$} (sum);
\draw [->] (sum) -- node {$e_{i}$} (controller);
\draw [->] (system) -- node [name=q] {$q_{i}$}(output);
\draw [->] (q) |- (filter);
\draw [->] (filter) -- node {} (sum2);
\draw [->] (controller) -- node {} (sum1);
\draw [->] (sum1) -- node[name=xi] {$\xi_{i}$} (filterinv);
\node [input, below of=sum1](input2) {};
\draw [draw,->] (input2) -- node {$r_{i}$} (sum2);
\draw [->] (sum2) -| node[pos=0.99] {$-$}
node [near end] {$\tilde{s}_i$} (sum);
\draw [->] (delay) -| node[] {}
node [near end] {} (sum1);
\draw [draw,->] (input1) -- node[pos=0.15] {$u_{i-1}$} (delay);
\draw [->] (u) |- node[pos=0.99] {$u_i$}
node [near end] {} (output1);
\end{tikzpicture}
答案1
您已经完成所有工作,因此我只需解释我在您的代码中所做的更改。
您使用了tikset
前面已被弃用的tikzstyle
(请参阅:应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?)。
right of =
第二个重大变化是用新的库替换语法right= of
(pgfmanualpositioning
中的“17.5.3 高级放置选项”部分)。并且还使用on grid
选项来更好地对齐所有元素。
正如我所用on grid
,inputs
和outputs
仍然被定义为节点inner sep=0pt
而不是coordinates
。on grid
选项无法按预期工作coordinates
(请参阅:TikZ 中的“网格”节点定位实际上是如何工作的?)
filter
和节点之间的错位sum2
是由于node distance
对sum
节点和所有其他节点使用不同的节点造成的。我保持了不同的距离,但放置了filter
交叉坐标(filter) at (sum2-|filterinv)
。
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{positioning,arrows}
\begin{document}
\tikzset{%
block/.style={draw, fill=white, rectangle,
minimum height=2em, minimum width=3em},
input/.style={inner sep=0pt},
output/.style={inner sep=0pt},
sum/.style = {draw, fill=white, circle, minimum size=2mm, node distance=1.5cm, inner sep=0pt},
pinstyle/.style = {pin edge={to-,thin,black}}
}
\begin{tikzpicture}[auto, node distance=2cm, on grid, >=latex']
\node[input] (input) {};
\node[input, above = of input] (input1) {};
\node [sum, right = of input] (sum) {};
\node [block, right = of sum] (controller) {$K(s)$};
\node [sum, right = of controller] (sum1) {};
\node [block, right = of sum1] (filterinv) {$H^{-1}(s)$};
\node [block, right = 2.5cm of filterinv] (system) {$G(s)$};
\node [output, right = of system] (output) {};
\node [output, above = of output] (output1) {};
\node [block, above = of controller] (delay) {$D(s)$};
\node [sum, below = of sum1] (sum2) {};
\node [block] (filter) at (sum2-|filterinv) {$H(s)$};
\draw [draw,->] (input) node[above right] {$s_{i-1}$} -- (sum);
\draw [->] (sum) -- node {$e_{i}$} (controller);
\draw [->] (controller) -- node {} (sum1);
\draw [->] (sum1) -- node[name=xi] {$\xi_{i}$} (filterinv);
\draw [->] (filterinv) -- node[name=u, pos=.3] {$u_{i}$} (system);
\draw [->] (system) -- (output) node [name=q, above left] {$q_{i}$};
\draw [->] ([xshift=-5mm]q.south) |- (filter);
\draw [->] (filter) -- node {} (sum2);
\draw [draw,<-] (sum2) -- ++(90:.6cm) node[above]{$L_i+r_i$};
\draw [->] (sum2) -| node[pos=0.99, right] {$-$}
node [pos=.25, above] {$\tilde{s}_i$} (sum);
\draw [draw,->] (input1) node[above right] (ui-1) {$u_{i-1}$} -- (delay);
\draw [->] (delay) -| node[] {}
node [near end] {} (sum1);
\draw [->] (u.east|-system) |-
(output1) node[above left] (ui) {$u_i$};
\node[text=red, above left= 5mm and 6mm of ui.west] (veh) {vehicle $i$};
\draw[red, dashed] (veh.east)-|(ui.west)|-([yshift=-3mm]filter.south)-|(ui-1.east)|-(veh.west);
\end{tikzpicture}
\end{document}