2

I am trying to build a simple block diagram using TikZ but haven't been successful. With some help from previous posts I have been able to get close to what I need. This is what I have so far:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{verbatim}
\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=3cm,>=latex']
    \node [input, name=rinput] (rinput) {};
    \node [sum, right of=rinput] (sum1) {};
    \node [block, right of=sum1] (controller) {$K(s)$};
    \node [block, above of=controller,node distance=1.3cm] (up){$H(s)$};
    \node [block, below of=controller,node distance=1.3cm] (rate) {$G(s)$};
    \node [sum, right of=controller,node distance=2cm] (sum2) {};
    \node [output, right of=sum2, node distance=2cm] (output) {};
    \draw [->] (rinput) -- node{$U(s)$} (sum1);
    \draw [->] (sum1) --node[name=z,anchor=north]{} (controller);
    \draw [->] (sum2) -- node [name=y] {$Y(s)$}(output);
    \draw [->] (z) |- (rate);
    \draw [->] (rate) -| (sum2);
    \draw [->] (z) |- (up);
    \draw [->] (up) -| (sum2);
    \end{tikzpicture}

\end{document}

The issue is that I am trying to get rid of the K(s) block as well as sum1 (where U(s) goes). Basically I want to directly connect the H(s) and G(s) blocks and have U(s) going to the center of that line. I am having difficulty removing K(s) since the other two blocks are defined in terms of K(s). Any hints would be greatly appreciated.

  • Welcome! Why not use above right and below right? – cfr Jun 5 '17 at 3:37
2

I don't know if this is exactly the output you're looking for, but with a tikz matrix you don't have to worry about where to position the nodes, TikZ does it for you:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows.meta,positioning,calc}
\usetikzlibrary{matrix}

\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}[>=latex]
        \matrix[column sep=2cm, row sep=.7cm] {%
            &\node [block] (up) {$H(s)$};\\
            \node [input] (rinput) {}; & \node[input] (sum1) {}; & \node [sum] (sum2) {}; & \node[output] (output) {};
            \\
            &\node [block] (rate) {$G(s)$};\\
        };  
        \draw [->] (rinput) -- node[above] {$U(s)$} (sum1);
        \draw (up) -- (rate);
        \draw [->] (sum2) -- node[above] {$Y(s)$} (output);
        \draw [->] (rate) -| (sum2);
        \draw [->] (up) -| (sum2);
    \end{tikzpicture}

\end{document}

enter image description here

Moreover, please note that you have loaded tikz twice in your MWE, and from the TikZ manual, para. 16.1:

Remark: The libraries arrows and arrows.spaced are deprecated. Use arrows.meta instead/additionally, which allows you to do all that the old libraries offered, plus much more.

I've used arrows.meta with latex but, of course you can choose what you like.

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.