如何让块相对于一条线居中?

如何让块相对于一条线居中?

我正在制作下面的框图,但我不知道如何移动或居中第一列的 4 个块,以便沿着 U 线上下有相同的数字

平均能量损失

\documentclass{article}
\usepackage{lscape}
\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=2cm,>=latex',scale=0.1]

    \node [input, name=rinput] (rinput) {};
    \node [sum, right of=rinput] (sum1) {};
    \node [block, right of=sum1] (controller) {$k_{p\beta}$};
    \node [block, above of=controller,node distance=1.3cm] (up){$\frac{k_{i\beta}}{s}$};
    \node [block, above of=up,node distance=1.3cm] (up2){$\frac{k_{i\beta}}{s}$};
    \node [block, below of=controller,node distance=1.3cm] (rate) {$sk_{d\beta}$};
    \node [sum, right of=controller,node distance=2cm] (sum2) {};
    \draw [->] (up2) -| (sum2);

    \node [block, right of=sum2,node distance=2cm] (system) 
{$\frac{a_{\beta 2}}{s+a_{\beta 1}}$};
    \node [output, right of=system, node distance=2cm] (output) {};
    \node [tmp, below of=controller] (tmp1){$H(s)$};
    \draw [->,color=white] (rinput) -- node{$R(s)$} (sum1);
    \draw [->,color=white] (sum1) --node[name=z,anchor=center]{} (controller);
    \draw [->] (controller) -- (sum2);
    \draw [->] (sum2) -- node{$U(s)$} (system);
    \draw [-] (system) -- node [name=y] {$Y(s)$}(output);
    \draw [->,color=white] (sum1) |- (rate);
    \draw [->] (rate) -| (sum2);
    \draw [->,color=white] (sum1) |- (up);
    \node [input, right of=output, node distance=2cm] (input2) {};
    \draw [->] (up) -| (sum2);
%    \draw [-] (output) -- node [name=y2] { }(sum2);
    \node [sum, right of=output] (sum2) {};
    \draw [->] (output) -- node [name=y2] { }(sum2);
    \node [block, right of=sum2] (controllera) {$k_{p\beta}$};
    \node [block, above of=controllera,node distance=1.3cm] (upa){$\frac{k_{i\beta}}{s}$};
    \node [block, below of=controllera,node distance=1.3cm] (ratea) {$sk_{d\beta}$};
   \draw [->] (sum2) |- node{$R1(s)$} (upa);
   \draw [->] (sum2) -- node{$R2(s)$} (controllera);
   \draw [->] (sum2) |- node{$R3(s)$} (ratea);
    \node [block, right of=controllera,node distance=2cm] (sumador) {};
   \draw [->] (upa) -| node{$ $} (sumador);
   \draw [->] (controllera) -- node{$R2(s)$} (sumador);
   \draw [->] (ratea) -| node{$R3(s)$} (sumador);
    \node [input, right of=sumador, node distance=2cm] (Salida) {$H(s)$};
   \draw [->] (sumador) --  (Salida);
    \end{tikzpicture}
\caption{EQ}

\end{document}

别介意标题或标签,我正在修复它。

谢谢。 在此处输入图片描述

答案1

使用坐标计算:

sum2更改节点的代码

\node [sum, right of=controller,node distance=2cm] (sum2) {};

\node [sum, right=of $(controller.east)!.5!(up.east)$, node distance=2cm] (sum2) {};

并调整\draw [->] (controller) -- (sum2);\draw [->] (controller) -| (sum2);

局限性:当节点数为偶数时,您必须手动选择一对对称节点。而且似乎必须先绘制这些控制节点,然后再绘制节点sum1

用一个matrix

将所有控制器节点包裹在 tikz 中,可以更轻松地实现垂直居中对齐matrix

    \matrix[nodes=block, row sep={1.3cm,between origins}, right of=sum1] (controllers) {
      \node (controller) {$k_{p\beta}$};    \\
      \node (up) {$\frac{k_{i\beta}}{s}$};  \\
      \node (up2) {$\frac{k_{i\beta}}{s}$}; \\
      \node (rate) {$sk_{d\beta}$};         \\
    };
    \node [sum, right of=controllers, node distance=2cm] (sum2) {};

完整示例

\documentclass{article}
\usepackage{lscape}
\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=2cm,>=latex',scale=0.1]
    \node [input, name=rinput] (rinput) {};
    \node [sum, right of=rinput] (sum1) {};
    \matrix[nodes=block, row sep={1.3cm,between origins}, right of=sum1] (controllers) {
      \node (controller) {$k_{p\beta}$};    \\
      \node (up) {$\frac{k_{i\beta}}{s}$};  \\
      \node (up2) {$\frac{k_{i\beta}}{s}$}; \\
      \node (rate) {$sk_{d\beta}$};         \\
    };
    \node [sum, right of=controllers, node distance=2cm] (sum2) {};
    \draw [->] (up2) -| (sum2);

    \node [block, right of=sum2,node distance=2cm] (system) 
{$\frac{a_{\beta 2}}{s+a_{\beta 1}}$};
    \node [output, right of=system, node distance=2cm] (output) {};
    \node [tmp, below of=controller] (tmp1){$H(s)$};
    \draw [->,color=white] (rinput) -- node{$R(s)$} (sum1);
    \draw [->,color=white] (sum1) --node[name=z,anchor=center]{} (controller);
    \draw [->] (controller) -| (sum2);
    \draw [->] (sum2) -- node{$U(s)$} (system);
    \draw [-] (system) -- node [name=y] {$Y(s)$}(output);
    \draw [->,color=white] (sum1) |- (rate);
    \draw [->] (rate) -| (sum2);
    \draw [->,color=white] (sum1) |- (up);
    \node [input, right of=output, node distance=2cm] (input2) {};
    \draw [->] (up) -| (sum2);
%    \draw [-] (output) -- node [name=y2] { }(sum2);
    \node [sum, right of=output] (sum2) {};
    \draw [->] (output) -- node [name=y2] { }(sum2);
    \node [block, right of=sum2] (controllera) {$k_{p\beta}$};
    \node [block, above of=controllera,node distance=1.3cm] (upa){$\frac{k_{i\beta}}{s}$};
    \node [block, below of=controllera,node distance=1.3cm] (ratea) {$sk_{d\beta}$};
   \draw [->] (sum2) |- node{$R1(s)$} (upa);
   \draw [->] (sum2) -- node{$R2(s)$} (controllera);
   \draw [->] (sum2) |- node{$R3(s)$} (ratea);
    \node [block, right of=controllera,node distance=2cm] (sumador) {};
   \draw [->] (upa) -| node{$ $} (sumador);
   \draw [->] (controllera) -- node{$R2(s)$} (sumador);
   \draw [->] (ratea) -| node{$R3(s)$} (sumador);
    \node [input, right of=sumador, node distance=2cm] (Salida) {$H(s)$};
   \draw [->] (sumador) --  (Salida);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

可能偏离主题...通过使用calcchainsTiZ 库一个可能的解决方案可以是:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                calc,chains, 
                positioning,
                quotes
                }
\tikzset{
block/.style = {draw, semithick, minimum size=3em, inner ysep=0pt},
  sum/.style = {circle, draw, minimum size=10pt, inner sep=0pt},
every edge/.style = {draw, ->}
        }

\begin{document}
    \begin{tikzpicture}[auto, 
node distance = 2mm and 11mm,
            > = Stealth,
  start chain = going below,       
            ]
    \begin{scope}[nodes={block, on chain}]
\node (m1) {$k_{i\beta}$};
\node (m2) {$\frac{k_{i\beta}}{s}$};
\node (m3) {$k_{p\beta}$};
\node (m4) {$sk_{d\beta}$};
    \end{scope} 
\coordinate[left=of $(m2.south)!0.5!(m3.north)$] (in);
%
\node (s1)  [sum] at (in) {~};
\node (s2)  [sum,  right=of in -| m3.east] {$+$};
\node (s3)  [block, right=of s2] {$\frac{a_{\beta 2}}{s+a_{\beta 1}}$};
\node (s4)  [sum,  right=of s3] {~};
%
\draw[->]   (m1) -| (s2);
\draw       (m2) -- (m2 -| s2);
\draw       (m3) -- (m3 -| s2);
\draw[->]   (m4) -| (s2);
%
\node (n2) [block, right=of s4]  {$\frac{k_{i\beta}}{s}$};
\node (n1) [block, above=of n2]  {$k_{p\beta}$};
\node (n3) [block, below=of n2]  {$sk_{d\beta}$};
%
\node (s5)  [block, right=of n2] {};
\coordinate[right=of s5] (out);
%
\draw[->]   (s4) |- (n1) node[pos=0.75,above] {$R_1(s)$};
\draw[->]   (s4) |- (n3) node[pos=0.75,above] {$R_3(s)$};
%
\draw[->]   (n1) -| (s5);
\draw[->]   (n3) -| (s5) node[pos=0.25,above] {$R_3(s)$};
%%%
\coordinate[right=of s5] (out);
\path   (s2) edge ["$U(s)$"] (s3)
        (s3) edge ["$Y(s)$"] (s4)
        (s4) edge ["$R_2(s)$"] (n2)
        (n2) edge ["$R_2(s)$"] (s5)
        (s5) edge (out);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容