节点位置

节点位置

如何更改 TikZ 中节点的长度?

\documentclass[border=0.9cm]{standalone}
 
% More defined colors
\usepackage[dvipsnames]{xcolor}
 
% Required package
\usepackage{tikz}
\usetikzlibrary{positioning}
 
 
\begin{document}
 
\begin{tikzpicture}
\node [draw,
    fill=Goldenrod,
    minimum width=2cm,
    minimum height=1.2cm,
]  (controller) {$C(s)$};
 
\node [draw,
    fill=SeaGreen, 
    minimum width=2cm, 
    minimum height=1.2cm, 
    below right= 0.5cm and -2cm of controller
]  (sensor) {$G(s)$};

        
\draw[-stealth] (controller.east) -| (sensor.east)
 node[midway,above]{$u$};

\draw[-stealth] (sensor.west) |- (controller.west)
 node[midway,above]{$u$};
    
\end{tikzpicture}
 
\end{document}

在此处输入图片描述

如何将这些线条与这些形状区分开?我想要像这样的东西 在此处输入图片描述

答案1

尝试

\draw[-stealth] (controller.east) -- +(0.5,0) |- node[pos=0.25,right]{$u$} (sensor.east);
\draw[-stealth] (sensor.west) -- +(-0.5,0) |- node[pos=0.25,left]{$u$} (controller.west);

+(0.5,0)指定相对于前一个点的新坐标,0.5向右单位。从那里您可以向下 ( |) 和向左 ( -) 到目标坐标。

在此处输入图片描述

\documentclass[border=0.9cm]{standalone}
 
% More defined colors
\usepackage[dvipsnames]{xcolor}
 
% Required package
\usepackage{tikz}
\usetikzlibrary{positioning}
 
 
\begin{document}
 
\begin{tikzpicture}
\node [draw,
    fill=Goldenrod,
    minimum width=2cm,
    minimum height=1.2cm,
]  (controller) {$C(s)$};
 
\node [draw,
    fill=SeaGreen, 
    minimum width=2cm, 
    minimum height=1.2cm, 
    below right= 0.5cm and -2cm of controller
]  (sensor) {$G(s)$};

        
\draw[-stealth] (controller.east) -- +(0.5,0) |- node[pos=0.25,right]{$u$} (sensor.east);
\draw[-stealth] (sensor.west) -- +(-0.5,0) |- node[pos=0.25,left]{$u$} (controller.west);
    
\end{tikzpicture}
 
\end{document}

相关内容