如何定位 TikZ 节点

如何定位 TikZ 节点

我怎样才能将system节点向右移动control1但垂直居中于control1和之间control2

\tikzstyle{controller} = [draw, fill=blue!20, rectangle, 
    minimum height=3em, minimum width=6em]
\tikzstyle{block} = [draw, fill=yellow!20, rectangle, 
    minimum height=3em, minimum width=6em]    
\tikzstyle{sum} = [draw, circle, node distance=1.5cm]
\tikzstyle{disturbance} = [draw=none, node distance=1.5cm, line width=0pt] 
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]

\node [input, name=input] {};
\node [sum, right of=input] (sum) {};    
\node [controller, right of=sum] (control1){Control1}; 
\node [controller, above of=control1] (control2) {Control2};
\node [block, right of= control1, node distance=5cm, yshift=-1.4cm] (system) {System};

答案1

您可以使用positioning库来代替已弃用的输入语法<direction> of =。请参阅此答案PGF/TikZ 中“right of=”和“right=of”之间的区别并且应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?

然后,您可以使用calc语法来获取两个节点的中间点。

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}[sum/.style={draw, circle, node distance=1.5cm},
               controller/.style={draw, fill=blue!20, rectangle, 
    minimum height=3em, minimum width=6em},
               block/.style={draw, fill=yellow!20, rectangle, 
    minimum height=3em, minimum width=6em}]
  \coordinate (input);
  \node [sum, right= of input] (sum) {};    
  \node [controller, right = of sum] (control1) {Control1}; 
  \node [controller, above = of control1] (control2) {Control2};
  \node [block, right= 5cm of {$(control1)!0.5!(control2)$}] (system) {System};
\end{tikzpicture}
\end{document}

在此处输入图片描述

并请发布完整的可编译代码。

相关内容