流程图自动对齐

流程图自动对齐

如果块中的文本“吹出”了它并且它的尺寸开始干扰其他块,那么如何进行自动对齐?

在此处输入图片描述

\documentclass[tikz,a4paper,border=1mm]{standalone}

\usepackage{pgfplots}
\usepackage{amsmath}

\usetikzlibrary{positioning,arrows}

\begin{document}

\tikzset{%
    block/.style={draw, fill=white, rectangle, 
            minimum height=2em, minimum width=3em},
    input/.style={inner sep=0pt},       
    output/.style={inner sep=0pt},      
    sum/.style = {draw, fill=white, circle, minimum size=2mm, node distance=1.5cm, inner sep=0pt},
    pinstyle/.style = {pin edge={to-,thin,black}}
}

\begin{tikzpicture}[auto, node distance=2cm, on grid, >=latex']

\node[input] (input) {};
\node[input, above = of input] (input1) {};
\node [sum, right = of input] (sum) {};
\node [block, right = of sum] (controller) {$K(s)$};
\node [block, right = of controller] (filterinv) {$H^{-1}(s)$};
\node [block, right = 2.5cm of filterinv] (system) {$\begin{cases} 3x + 5y + z \\ 7x – 2y + 4z \\ -6x + 3y + 2z \end{cases}$};
\node [output, right = of system] (output) {};
\node [output, above = of output] (output1) {};
\node [block, below = of filterinv] (filter) {$H(s)$};

\draw [draw,->] (input) node[above right] {$s_{i-1}$} -- (sum);
\draw [->] (sum) -- node {$e_{i}$} (controller);
\draw [->] (controller) -- node[name=xi] {$\xi_{i}$} (filterinv);
\draw [->] (filterinv) -- node[name=u, pos=.3] {$u_{i}$} (system);
\draw [->] (system) -- (output) node [name=q, above left] {$q_{i}$};

\draw [->] ([xshift=-5mm]q.south) |- (filter);
\draw [->] (filter) -| node[pos=0.99, right] {$-$} 
    node [pos=.25, above] {} (sum);

\draw [->] (u.east|-system) |-  
    (output1) node[above left] (ui) {$u_i$};

\end{tikzpicture}
\end{document}

编辑:

\documentclass[tikz,a4paper,border=1mm]{standalone}

\usepackage{pgfplots}
\usepackage{amsmath}

\usetikzlibrary{positioning,arrows}

\begin{document}

\tikzset{%
    block/.style={draw, fill=white, rectangle, 
            minimum height=2em, minimum width=3em},
    input/.style={inner sep=0pt},       
    output/.style={inner sep=0pt},      
    sum/.style = {draw, fill=white, circle, minimum size=2mm, node distance=1.5cm, inner sep=0pt},
    pinstyle/.style = {pin edge={to-,thin,black}}
}

\begin{tikzpicture}[auto, node distance=1cm, >=latex']

\node[input] (input) {};
\node[input, above = of input] (input1) {};
\node [sum, right = of input] (sum) {};
\node [block, right = of sum] (system) {$\begin{cases}  \dot{\vec{x}}_i=f_i(\vec{x}_i,t)+g_i(\vec{x}_i,t)u(t) \\ y=h_i(\vec{x}_i,t)\end{cases}$};
\node [output, right = of system] (output) {};
\node [output, above = of output] (output1) {};
\node [block, below = of system] (controller) {$K(s)$};

\draw [draw,->] (input) node[above right] {$0$} -- (sum);
\draw [->] (sum) -- node {$e_{i}$} (system);
\draw [->] (system) -- (output) node [name=q, above left] {$y$};

\draw [->] ([xshift=-5mm]q.south) |- node {$x$} (controller);

\draw [->] (controller) -| node[pos=0.99, right] {$-$} 
    node [pos=.25, above] {$s$} (sum);


\end{tikzpicture}
\end{document}

在此处输入图片描述

如何添加$x$从节点开始$K(s)$并将点添加到节点?

答案1

通过使用chains主分支上的节点库,您将不会遇到节点之间等距间距的问题:

在此处输入图片描述

\documentclass[preview, border=3.141592mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                positioning,
                quotes}
\tikzset{cntrl/.style = {
            > = Stealth,
node distance = 4mm and 8mm,
   box/.style = {draw, minimum size=7mm},
     C/.style = {circle, draw, minimum size=4mm},
   dot/.style = {circle, fill, inner sep=2pt},
every edge/.append style = {draw, ->},
  start chain
        }   }
\usepackage{amsmath}

\begin{document}
First image:

    \begin{tikzpicture}[cntrl]
    \begin{scope}[nodes={on chain=going right}]
\coordinate (in) {};
\node   (sum)       [C]     {};
\node   (controller)[box]   {$K(s)$};
\node   (filterinv) [box]   {$H^{-1}(s)$};
\node   (aux1)      [dot]   {};
\node   (system)    [box]   {$\begin{cases} 
                                3x + 5y + z \\ 
                                7x – 2y + 4z \\ 
                                -6x + 3y + 2z 
                              \end{cases}$};
\node (aux2)        [dot]   {};
\coordinate (out);
    \end{scope}
\coordinate[above=of system.north -| out] (ui);
\node(filter)   [box, below=of filterinv] {$H(s)$};
%
\draw   (in)        edge["$s_{i-1}$"]   (sum) 
        (sum)       edge["$e_{i}$"]     (controller)
        (controller)edge["$\xi_{i}$"]   (filterinv)
        (filterinv) edge[pos=0.25, "$u_{i}$"]   (system)
        (system)    edge[pos=0.75, "$q_{i}$"]     (out);
\draw[->] (aux1) |- (ui)        node[above left] {$u_i$};
%
\draw[->]   (aux2) |- (filter.east)  node[above right] {$x$};
\draw[->]   (filter) -| (sum)   node[below right] {$-$};
    \end{tikzpicture}
    
Second image:

    \begin{tikzpicture}[cntrl]
    \begin{scope}[nodes={on chain=going right}]
\coordinate (in) {};
\node   (sum)       [C]     {};
\node   (system)    [box]   {$\begin{cases}
                        \dot{\vec{x}}_i = f_i(\vec{x}_i,t)+g_i(\vec{x}_i,t)u(t) \\
                                      y = h_i(\vec{x}_i,t)
                              \end{cases}$};
\node   (dot)       [dot]   {};
\coordinate (out);
    \end{scope}
\node(filter)   [box, below=of system] {$K(s)$};
%
\draw   (in)        edge["$s_{i-1}$"]   (sum)
        (sum)       edge["$e_{i}$"]     (system)
        (system)    edge[pos=0.25, "$q_{i}$"]   (out);
%
\draw[->]   (dot)    |- (filter.east)   node[above right]   {$x$};
\draw[->]   (filter) -| (sum)           node[pos=0.25,above] {$s$}
                                        node[below right]   {$-$};
    \end{tikzpicture}
\end{document}

答案2

我会放弃该on grid选项,稍微减少节点距离,并移除节点的额外移位(system)。但是,如果您的图表更复杂,您可能需要手动移动节点。

\documentclass[tikz,a4paper,border=1mm]{standalone}

\usepackage{pgfplots}
\usepackage{amsmath}

\usetikzlibrary{positioning,arrows}

\begin{document}

\tikzset{%
    block/.style={draw, fill=white, rectangle, 
            minimum height=2em, minimum width=3em},
    input/.style={inner sep=0pt},       
    output/.style={inner sep=0pt},      
    sum/.style = {draw, fill=white, circle, minimum size=2mm, node distance=1.5cm, inner sep=0pt},
    pinstyle/.style = {pin edge={to-,thin,black}}
}

\begin{tikzpicture}[auto, node distance=1cm, >=latex']

\node[input] (input) {};
\node[input, above = of input] (input1) {};
\node [sum, right = of input] (sum) {};
\node [block, right = of sum] (controller) {$K(s)$};
\node [block, right = of controller] (filterinv) {$H^{-1}(s)$};
\node [block, right = of filterinv] (system) {$\begin{cases} 3x + 5y + z \\ 7x – 2y + 4z \\ -6x + 3y + 2z \end{cases}$};
\node [output, right = of system] (output) {};
\node [output, above = of output] (output1) {};
\node [block, below = of filterinv] (filter) {$H(s)$};

\draw [draw,->] (input) node[above right] {$s_{i-1}$} -- (sum);
\draw [->] (sum) -- node {$e_{i}$} (controller);
\draw [->] (controller) -- node[name=xi] {$\xi_{i}$} (filterinv);
\draw [->] (filterinv) -- node[name=u, pos=.3] {$u_{i}$} (system);
\draw [->] (system) -- (output) node [name=q, above left] {$q_{i}$};

\draw [->] ([xshift=-5mm]q.south) |- (filter);
\draw [->] (filter) -| node[pos=0.99, right] {$-$} 
    node [pos=.25, above] {} (sum);

\draw [->] (u.east|-system) |-  
    (output1) node[above left] (ui) {$u_i$};

\end{tikzpicture}
\end{document}

在此处输入图片描述


考虑到OP的编辑:

\documentclass[tikz,a4paper,border=1mm]{standalone}

\usepackage{pgfplots}
\usepackage{amsmath}

\usetikzlibrary{positioning,arrows}

\begin{document}

\tikzset{%
    block/.style={draw, fill=white, rectangle, 
            minimum height=2em, minimum width=3em},
    input/.style={inner sep=0pt},       
    output/.style={inner sep=0pt},      
    sum/.style = {draw, fill=white, circle, minimum size=2mm, node distance=1.5cm, inner sep=0pt},
    pinstyle/.style = {pin edge={to-,thin,black}}
}

\begin{tikzpicture}[auto, node distance=1cm, >=latex']

\node[input] (input) {};
\node [sum, right = of input] (sum) {};
\node [block, right = of sum] (system) {$\begin{cases}  \dot{\vec{x}}_i=f_i(\vec{x}_i,t)+g_i(\vec{x}_i,t)u(t) \\ y=h_i(\vec{x}_i,t)\end{cases}$};
\node [sum, right = of system] (sum2) {};
\node [output, right = of sum2] (output) {};
\node [block, below = of system] (controller) {$K(s)$};

\draw [draw,->] (input) node[above right] {$0$} -- (sum);
\draw [->] (sum) -- node {$e_{i}$} (system);
\draw (system) -- (sum2); 
\draw [->] (sum2) -- (output) node [name=q, above left] {$y$};

\draw [->] (sum2) |- node[pos=.75, above] {$x$} (controller);

\draw [->] (controller) -| node[pos=0.99, right] {$-$} node [pos=.25, above] {$s$} (sum);

\end{tikzpicture}

\end{document}

在此处输入图片描述


考虑到 OP 的补充评论(抱歉,我无法准确读懂所使用的符号):

\documentclass[tikz,a4paper,border=1mm]{standalone}

\usepackage{pgfplots}
\usepackage{amsmath}

\usetikzlibrary{positioning,arrows}

\begin{document}

\tikzset{%
    block/.style={draw, fill=white, rectangle, 
            minimum height=2em, minimum width=3em},
    input/.style={inner sep=0pt},       
    output/.style={inner sep=0pt},      
    sum/.style = {draw, fill=white, circle, minimum size=2mm, node distance=1.5cm, inner sep=0pt},
    pinstyle/.style = {pin edge={to-,thin,black}}
}

\begin{tikzpicture}[auto, node distance=1cm, >=latex']

\node[input] (input) {};
\node [sum, right = of input] (sum) {};
\node [block, right = of sum] (system1) {$ \alpha(\zeta, x) + \beta(\zeta, x)w $};
\node [block, above = of system1] (system2) {$ \dot{\zeta} = A\zeta + Bw $};
\node [block, right = of system1] (system3) {$ \begin{aligned} \dot{x} &= f(x) + g(x)u \\ \dot{y} &= h(x) \end{aligned} $};
\node [output, right = of system3] (output) {};

\draw [draw,->] (input) node[above right] {$w$} -- (sum);
\draw [->] (sum) -- (system1);
\draw [->] (sum) |- (system2);
\draw [->] (system2) -- node[right] {$\zeta$} (system1);
\draw [->] (system1) -- node[above] {$u$} (system3);
\draw [->] (system3) -- (output) node [above left] {$y$};
\draw [->] (system3) |- ++(0,-1) -| (system1) node [right, pos=.75] {$x$};

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容