我正在尝试使用 TikZ 构建一个简单的框图,但没有成功。在之前帖子的帮助下,我已经能够接近我需要的了。这是我目前所拥有的:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}
\begin{document}
\tikzset{
block/.style = {draw, fill=white, rectangle, minimum height=3em, minimum width=3em},
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}
}
}
\begin{tikzpicture}[auto, node distance=3cm,>=latex']
\node [input, name=rinput] (rinput) {};
\node [sum, right of=rinput] (sum1) {};
\node [block, right of=sum1] (controller) {$K(s)$};
\node [block, above of=controller,node distance=1.3cm] (up){$H(s)$};
\node [block, below of=controller,node distance=1.3cm] (rate) {$G(s)$};
\node [sum, right of=controller,node distance=2cm] (sum2) {};
\node [output, right of=sum2, node distance=2cm] (output) {};
\draw [->] (rinput) -- node{$U(s)$} (sum1);
\draw [->] (sum1) --node[name=z,anchor=north]{} (controller);
\draw [->] (sum2) -- node [name=y] {$Y(s)$}(output);
\draw [->] (z) |- (rate);
\draw [->] (rate) -| (sum2);
\draw [->] (z) |- (up);
\draw [->] (up) -| (sum2);
\end{tikzpicture}
\end{document}
问题是我试图摆脱 K(s) 块以及 sum1(U(s) 所在的位置)。基本上,我想直接连接 H(s) 和 G(s) 块,并让 U(s) 位于该线的中心。我很难移除 K(s),因为其他两个块是根据 K(s) 定义的。任何提示都将不胜感激。
答案1
我不知道这是否正是您想要的输出,但tikz matrix
您不必担心节点的位置,TikZ 会为您完成:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows.meta,positioning,calc}
\usetikzlibrary{matrix}
\begin{document}
\tikzset{
block/.style = {draw, fill=white, rectangle, minimum height=3em, minimum width=3em},
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}
}
}
\begin{tikzpicture}[>=latex]
\matrix[column sep=2cm, row sep=.7cm] {%
&\node [block] (up) {$H(s)$};\\
\node [input] (rinput) {}; & \node[input] (sum1) {}; & \node [sum] (sum2) {}; & \node[output] (output) {};
\\
&\node [block] (rate) {$G(s)$};\\
};
\draw [->] (rinput) -- node[above] {$U(s)$} (sum1);
\draw (up) -- (rate);
\draw [->] (sum2) -- node[above] {$Y(s)$} (output);
\draw [->] (rate) -| (sum2);
\draw [->] (up) -| (sum2);
\end{tikzpicture}
\end{document}
此外,请注意您已tikz
在 MWE 中加载两次,并且来自 TikZ 手册第 16.1 段:
备注:arrows 和 arrows.spaced 库已弃用。请改用/另外使用 arrows.meta,它允许您执行旧库提供的所有功能以及更多功能。
我已经用过了arrows.meta
,latex
但是当然你可以选择你喜欢的。