我有一个非常简单的开环图和一个闭环图的代码
Y(s) 下的反馈回路的输出线太短,我想将其延长 1 厘米。但是,如果我将 Tikz 中的线从
output/.style = {coordinate,node distance=1cm},
到
output/.style = {coordinate,node distance=2cm},
然后上面的图也发生了变化,所以现在开环图的输出线太长了。
如何为 Tikz 中的每个图表声明多个 Tikz 集?即不同图表使用不同的规格。或者是否有其他解决方案可以本地用于每个图表?
请提供帮助,愿上帝拯救美国。
\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=1cm},
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] {$U(s)$};
\node [block, right=of input] (controller) {$C(s)$};
\node [block, right=of controller] (plant) {$G(s)$};
\node [output, right=of plant] (output) {};
\draw [->] (input) -- node {$U(s)$} (controller);
\draw [->] (controller) -- (plant);
\draw [->] (plant) -- node [name = y] {$Y(s)$} (output);
\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}
答案1
钛钾可以在文档中间使用\tikzset
或甚至通过可选参数创建/更改 Z 样式tikzpicture
与之前创建的方式相同。
所以如果你想只是第二张图片有一个node distance
,2cm
你可以改变output
风格在\tikzset
该图片使用tikzpicture
环境或环境的可选部分,这些都是局部变化。
如果要全局更改设置output
,请\tikzset
在tikzpicture
,则发布之后的所有图片\tikzset
都会继承该样式设置。
请参阅此 MWE 作为示例:
\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=1cm},
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] {$U(s)$};
\node [block, right=of input] (controller) {$C(s)$};
\node [block, right=of controller] (plant) {$G(s)$};
\node [output, right=of plant] (output) {};
\draw [->] (input) -- node {$U(s)$} (controller);
\draw [->] (controller) -- (plant);
\draw [->] (plant) -- node [name = y] {$Y(s)$} (output);
\end{tikzpicture}
% \tikzset{output/.style = {node distance=2cm}} %<< global change (uncomment to see the difference)
\begin{tikzpicture}[auto,
node distance=1cm,
>=latex',
output/.style = {node distance=2cm}] % << local change
\tikzset{output/.style = {node distance=2cm}} %<< also local change
\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}
\begin{tikzpicture}[auto, node distance=1cm,>=latex']
\node [input, name=input] {$U(s)$};
\node [block, right=of input] (controller) {$C(s)$};
\node [block, right=of controller] (plant) {$G(s)$};
\node [output, right=of plant] (output) {};
\draw [->] (input) -- node {$U(s)$} (controller);
\draw [->] (controller) -- (plant);
\draw [->] (plant) -- node [name = y] {$Y(s)$} (output);
\end{tikzpicture}
\end{center}
\caption{TikzPicture}\label{fig}
\end{figure}
\end{document}