我有一个 Tikz 中的反馈系统图的工作示例
我一直在摆弄代码,但是每当我做某事时我都会收到错误,而且我不知道如何使用|- 和 -|。
有人可以帮助我执行以下操作:
将 C(s) 和 G(s) 之间的线再拉长一些(现在太短了)
将 1 放置在反馈回路中,位于连接 C(s) 和 G(s) 的线的中间正下方(更对称)
将 1 全部删除,只留下一个没有任何块的循环
\documentclass[]{article} \usepackage{tikz} \usetikzlibrary{shapes,arrows} \usetikzlibrary{arrows,calc} \tikzset{ block/.style = {draw, rectangle, minimum height=1cm, minimum width=2cm}, input/.style = {coordinate,node distance=1cm}, output/.style = {coordinate,node distance=4cm}, arrow/.style={draw, -latex,node distance=2cm}, pinstyle/.style = {pin edge={latex-, black,node distance=2cm}}, sum/.style = {draw, circle, node distance=1cm} } \begin{document} \begin{figure}[ht] \begin{center} \begin{tikzpicture}[auto, node distance=2.5cm,>=latex'] \node [input, name=input] {}; \node [sum, right of=input] (sum) {}; \node [block, right of=sum] (controller) {$C(s)$}; \node [block, right of=controller] (plant) {$G(s)$}; \node [output, right of=plant] (output) {}; \node [block, below of=plant] (feedback) {$1$}; \draw [draw,->] (input) -- node {$U(s)$} (sum); \draw [->] (sum) -- node {} (controller); \draw [->] (controller) -- node {} (plant); \draw [->] (plant) -- node [name=y] {$Y(s)$}(output); \draw [->] (y) |- node [above,pos=0.79] {} (feedback) ; \draw [->] (feedback) -| node[pos=0.99] {$-$} node [near end] {} (sum); \end{tikzpicture} \end{center} \caption{TikzPicture}\label{fig} \end{figure} \end{document}
答案1
- 您可以使用 tikzlibrary 定位语法,
[left=n of N]
其中 n 是节点距离,N 是应相对于定位的节点。 - 使用 calc 库,如下所示。
- 使用相对坐标分两步绘制边缘。
\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{arrows,calc,positioning}
\tikzset{
block/.style = {draw, rectangle,
minimum height=1cm,
minimum width=2cm},
input/.style = {coordinate,node distance=1cm},
output/.style = {coordinate,node distance=4cm},
arrow/.style={draw, -latex,node distance=2cm},
pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
sum/.style = {draw, circle, node distance=1cm},
}
\begin{document}
\begin{figure}[ht]
\begin{center}
\begin{tikzpicture}[auto, node distance=1cm,>=latex']
\node [input, name=input] {};
\node [sum, right=of input] (sum) {};
\node [block, right=of sum] (controller) {$C(s)$};
\node [block, right=2 of controller] (plant) {$G(s)$};
\node [output, right=of plant] (output) {};
\node at ($(controller)!0.5!(plant)+(0,-2)$) [block] (feedback) {$1$};
\draw [draw,->] (input) -- node {$U(s)$} (sum);
\draw [->] (sum) -- (controller);
\draw [->] (controller) -- (plant);
\draw [->] (plant) -- node [name=y] {$Y(s)$}(output);
\draw [->] (y) |- (feedback) ;
\draw [->] (feedback) -| node[pos=0.99] {$-$} (sum);
\end{tikzpicture}
\begin{tikzpicture}[auto, node distance=1cm,>=latex']
\node [input, name=input] {};
\node [sum, right=of input] (sum) {};
\node [block, right=of sum] (controller) {$C(s)$};
\node [block, right=2 of controller] (plant) {$G(s)$};
\node [output, right=of plant] (output) {};
\draw [draw,->] (input) -- node {$U(s)$} (sum);
\draw [->] (sum) -- node {} (controller);
\draw [->] (controller) -- node {} (plant);
\draw [->] (plant) -- node [name=y] {$Y(s)$}(output);
\draw [->] (y) -- ++ (0,-2) -| node [pos=0.99] {$-$} (sum);
\end{tikzpicture}
\end{center}
\caption{TikzPicture}\label{fig}
\end{figure}
\end{document}