6

I have the following block diagram enter image description here

I am interested how to create red node like in my picture?

Here is my code:

  \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=5cm},
        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] {};
            \node [sum, right=of input] (sum) {};
            
            \node [draw=black,
                    minimum width=2.5cm,
                    minimum height=1.5cm,
                     right=1cm of sum]  (controller){1};
            \node [draw=black,
                    minimum width=2.5cm,
                    minimum height=1.5cm,
                    right=1cm of controller]  (plant){2};
            \node [draw=black,
                    minimum width=2.5cm,
                    minimum height=1.5cm,
                    right=1cm of plant]  (plant1){3};                    
  

            \node [minimum width=2.5cm,
                    minimum height=1.5cm, output, right=of plant] (output) {};
            \node at ($(controller)!1.5!(plant)+(0,-2.5)$) [block] (feedback) {4};
            
            
            \draw [draw,->] (input) -- node {$r$} (sum);
            \draw [->] (sum) -- (controller);
            \draw [->] (controller) -- node {$v$} (plant);
            \draw [->] (feedback) -- node {$u$} (plant);
            \draw [->] (plant) -- node {$u$} (plant1);
            \draw [->] (plant1) -- node [name=y] {$x$}(output);
            \draw [->] (y) |- (feedback) ;
            \draw [->] (feedback) -| node[pos=0.99] {$-$} (sum);
            \end{tikzpicture}    
        
        \end{center}
        \caption{TikzPicture}\label{fig}
    \end{figure}
    \end{document}
1
  • Why you not simple move block 4 below of block 2? Than arrow between them is straight ;-)
    – Zarko
    Jun 12, 2022 at 10:54

2 Answers 2

10

Change

\draw [->] (feedback) -- node {$u$} (plant);

to

\draw [->] (feedback) 
  |- ($ (feedback.north)!.5!(plant.south) $) 
  -| node[pos=0, swap] {$u$} (plant);

Doc for partway coordinate calculation ($ <coord1>!<factor>!<coord2> $): pgfmanual, sec. 13.5.3  The Syntax of Partway Modifiers (html). enter image description here

Full example

\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=5cm},
    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] {};
        \node [sum, right=of input] (sum) {};
        
        \node [draw=black,
                minimum width=2.5cm,
                minimum height=1.5cm,
                 right=1cm of sum]  (controller){1};
        \node [draw=black,
                minimum width=2.5cm,
                minimum height=1.5cm,
                right=1cm of controller]  (plant){2};
        \node [draw=black,
                minimum width=2.5cm,
                minimum height=1.5cm,
                right=1cm of plant]  (plant1){3};                    


        \node [minimum width=2.5cm,
                minimum height=1.5cm, output, right=of plant] (output) {};
        \node at ($(controller)!1.5!(plant)+(0,-2.5)$) [block] (feedback) {4};
        
        
        \draw [draw,->] (input) -- node {$r$} (sum);
        \draw [->] (sum) -- (controller);
        \draw [->] (controller) -- node {$v$} (plant);
        \draw [->] (feedback) |- ($ (feedback.north)!.5!(plant.south) $) -| node[pos=0, swap] {$u$} (plant);
        \draw [->] (plant) -- node {$u$} (plant1);
        \draw [->] (plant1) -- node [name=y] {$x$}(output);
        \draw [->] (y) |- (feedback) ;
        \draw [->] (feedback) -| node[pos=0.99] {$-$} (sum);
        \end{tikzpicture}    
    
    \end{center}
    \caption{TikzPicture}\label{fig}
\end{figure}
\end{document}
5

I would positioned feedback block (4) below of controller (3) and at drawing of image employ libraries arrows.meta, chains, positioning and quotes:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                positioning,
                quotes}

    \tikzset{
block/.style = {draw, minimum height=1cm, minimum width=2cm},
  arr/.style = {draw, -Latex},
              every edge/.style = {arr},
  dot/.style = {circle, fill, inner sep=2pt},
every edge quotes/.append style = {auto, font=\small},
  sum/.style = {draw, circle}
            }

\begin{document}
    \begin{figure}[ht]
    \centering
    \begin{tikzpicture}[
node distance = 11mm and 11mm,
  start chain = going right
                        ]
    \begin{scope}[nodes={on chain}]
\coordinate (in)    {};
\node   [sum]   (sum)           {};
\node   [block] (controller)    {1};
\node   [block] (plant)         {2};
\node   [block] (plant1)        {3};
\node   [dot]   (dot)           {};
\coordinate (out);
    \end{scope}
\node   [block, 
         below=of plant] (feedback) {4};
%%%%
\draw   (in)            edge ["$r$"]    (sum) 
        (sum)           edge            (controller) 
        (controller)    edge ["$v$"]    (plant) 
        (feedback)      edge ["$u$"]    (plant) 
        (plant)         edge ["$u$"]    (plant1) 
        (plant1)        edge [pos=0.75, "$x$"]    (out);   
\draw[arr]  (dot) |- (feedback);
\draw[arr] (feedback) -| (sum) node[pos=0.99] {$-$};
    \end{tikzpicture}
\caption{TikzPicture}
\label{fig}
    \end{figure}
\end{document}

enter image description here

1
  • Haha, I wanted to have that line, ofc I tried that already :D, but thank you
    – lra
    Jun 12, 2022 at 16:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .