0

Hello I was wondering how to do block diagrams in Latex. I am a beginner to the program so I am pretty remedial at it so far. I want to create

enter image description here

just without the bold lines or gray blocks. I am having trouble connecting everything and putting blocks in parallel or series. So far I have only been able to do a very simple one. Can I get some help please, thank you.

     \tikzset{
block/.style={
  draw, 
  fill=blue!20, 
  rectangle, 
  minimum height=3em, 
  minimum width=6em
  },
sum/.style={
  draw, 
  fill=blue!20, 
  circle, 
  },
input/.style={coordinate},
output/.style={coordinate},
pinstyle/.style={
  pin edge={to-,thin,black}
  }
}  


% The block diagram code is probably more verbose than necessary
\begin{center}

\begin{tikzpicture}[auto,>=latex']
    % We start by placing the blocks
    \node [input, name=input] {};
    \node [sum, right = of input] (sum) {};
    \node [block, right = of sum] (controller) {$K_d$};
    \node [block, right = of controller, pin={[pinstyle]above:$f(t)$},
            node distance=3cm] (system) {$G(s)$};
    % We draw an edge between the controller and system block to 
    % calculate the coordinate u. We need it to place the measurement block. 
    \draw [->] (controller) -- node[name=u] {} (system);
    \node [output, right =of system] (output) {};
    %\node [block, below of=u] (measurements) {Measurements};

    % Once the nodes are placed, connecting them is easy. 
    \draw [draw,->] (input) -- node {$r$} (sum);
    \draw [->] (sum) -- node {} (controller);
    \draw [->] (system) -- node [name=y] {$x$}(output);
    \draw [->] (y) -- ++(0,-2cm) -| node[pos=0.99] {} 
        node [near end] {} (sum);
\end{tikzpicture}
1
2

Here is one way. It uses a chain, and you can change the edge labels on the spot with [el=<label>]. By "upgrading" styles when necessary we can thus avoid having to add all the joins by hand.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,chains}
\begin{document}

\begin{center}

\begin{tikzpicture}[auto,>=Latex,
    cnode/.style={},    
    block/.style={cnode,
      draw, 
      fill=blue!20, 
      rectangle, 
      minimum height=3em, 
      minimum width=6em
      },
      tblock/.style={block,minimum width=2em},
    sum/.style={cnode,
      draw, 
      fill=blue!20, 
      circle, 
      },
    input/.style={coordinate,cnode},
    output/.style={coordinate,cnode},
    arj/.style={-Latex,semithick}]
    %
    \begin{scope}[start chain=R going right,
        cnode/.append style={join=by arj,on chain},
        node distance=2.5em,
        arj/.append style={edge label=\pgfkeysvalueof{/tikz/el}},
        el/.initial={}]
     \path node[input]{}    
          [el={$r$}]    
          node[tblock,alias=Nbar]{$\overline{N}$}
          [el={}]
          node[sum,label=above left:{$+$},label=below right:{$-$}]{}
          [el={$u$}]
          node[tblock,alias=B]{$B$}
          [el={},arj/.append style={very thick}]
          node[sum,label=above left:{$+$},label=below right:{$+$}]{}
          [el={$\dot x$}]
          node[tblock,alias=o]{$1/s$}
          [el={$x$}]
          node[tblock,alias=C,xshift=3em]{$C$}
          [el={$y$}]
          node[output]{};    
    \end{scope}
    %
    \begin{scope}[start chain=D going below,
        cnode/.append style={on chain},
        node distance=2.5em]
     \chainin (o);
     \node[tblock,alias=A]{$A$};    
     \node[tblock,alias=K]{$K$};    
    \end{scope}     
    %
    \path (o) -- (C) coordinate[pos=1/3] (oC1) coordinate[pos=2/3] (oC2);
    \draw[arj] (K) -| (R-2);
    \tikzset{arj/.append style={very thick}}
    \draw[arj] (A) -| (R-5);
    \draw[arj] (oC1) |- (A);
    \draw[arj] (oC2) |- (K);
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

3
  • You can use ctan.org/pkg/schemabloc
    – rpapa
    May 16 '20 at 6:41
  • 1
    @rpapa Merci! If you post an answer I can study it... ;-)
    – user194703
    May 16 '20 at 6:43
  • the answer is below
    – rpapa
    May 18 '20 at 7:25
1

Another way is:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                chains,
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
node distance = 4mm and 6mm,
  start chain = going right,
  base/.style = {draw, fill=blue!20},
 block/.style = {base, minimum height=2em, minimum width=3em},
   sum/.style = {base, circle, node contents={}},
   arr/.style = {ultra thick, -{Latex[length=5pt, width=6pt]}},
every edge/.style = {draw, -Latex},
                        ]
% We start by placing the blocks in chain
    \begin{scope}[nodes={on chain}]
\coordinate (in);
\node (n1)  [block]    {$\bar{N}$};
\node (n2)  [sum];
\node (n3)  [block]  {$B$};
\node (n4)  [sum];
\node (n5)  [block]  {$1/s$};
\coordinate (n6);
\coordinate (n7);
\node (n8) [block]     {$C$};
\coordinate (out);
    \end{scope}
%
\path   (in) edge["$r$"]   (n1)
        (n1) edge[near end,"+"] (n2)
        (n2) edge["$u$"]                    (n3)
        (n3) edge[arr,near end,"+"]         (n4)
        (n4) edge[arr,"$\dot{\mathbf{x}}$"] (n5)
        (n5) edge[arr,"$\mathbf{x}$"]       (n8)
        (n8) edge[arr,"$\mathbf{y}$"]       (out);
% Block in backloops
\node (n11)  [block, below=of n5]  {$A$};
\node (n12)  [block, below=of n11] {$K$};
%       
\draw[arr]  (n6)  |- (n11);
\draw[arr]  (n11) -| (n4) node[below right] {$+$};
\draw[arr]  (n7)  |- (n12);
\draw[-Latex]  (n12) -| (n2) node[below right] {$-$};
\end{tikzpicture}
\end{document}

enter image description here

1

Here is a proposal using the block diagram package on the ctan.

https://ctan.org/pkg/schemabloc

\documentclass{article}
\usepackage{schemabloc}


\begin{document}

\begin{tikzpicture}

\sbEntree{E}
\sbBlocL{B1}{$\overline{N}$}{E}
    \sbRelier[$r$]{E}{B1}
\sbComp*{C1}{B1}
    \sbRelier{B1}{C1}
\sbStyleBloc{blue,very thick,fill=yellow,text=red}%
\sbBloc{B2}{$B$}{C1}
    \sbRelier[$u$]{C1}{B2}
\sbSumb*{C2}{B2}
    \sbRelier{B2}{C2}
\sbBloc{B3}{$\frac{1}{s}$}{C2}
    \sbRelier[$\dot{x}$]{C2}{B3}
\sbBloc[6]{B4}{$C$}{B3}
    \sbRelier[$x$]{B3}{B4}
\sbSortie[4]{Y}{B4}

\sbStyleBloc{very thick,fill=green,text=blue}%
    \sbRelier[$y$]{B4}{Y}
    \sbDecaleNoeudy{B3}{R3}
\sbStyleLien{ultra thick, red}
    \sbBlocr[-1.5]{R3}{$A$}{R3}
        \sbRelieryx{B3-B4}{R3}
        \sbRelierxy{R3}{C2}
    \sbDecaleNoeudy[9]{B3}{R4}
    \sbBlocr[-1.5]{R4}{$K$}{R4}
        \sbRelieryx{B3-B4}{R4}
        \sbRelierxy{R4}{C1}
\end{tikzpicture}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.