5

I created a block diagram but I don't know how to adjust some of the distances.

\documentclass[tikz, convert = false]{standalone}

\usepackage[utf8]{inputenx}%  http://ctan.org/pkg/inputenx
% Euler for math | Palatino for rm | Helvetica for ss | Courier for tt
\renewcommand{\rmdefault}{ppl}% rm
\linespread{1.05}% Palatino needs more leading
\usepackage[scaled]{helvet}% ss //  http://ctan.org/pkg/helvet
\usepackage{courier}% tt // http://ctan.org/pkg/courier
\usepackage{eulervm}  %  http://ctan.org/pkg/eulervm
% a better implementation of the euler package (not in gwTeX)
\normalfont%
\usepackage[T1]{fontenc}%  http://ctan.org/pkg/fontenc
\usepackage{textcomp}%  http://ctan.org/pkg/textcomp

\usetikzlibrary{shapes, arrows}

\begin{document}
\tikzstyle{block} = [draw, rectangle, minimum height = 2em, minimum width = 3em]
\tikzstyle{sum} = [draw, circle, node distance = 1.25cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]

\begin{tikzpicture}[auto, node distance = 2cm]
  \node[input, name = input] {};
  \node[sum, right of = input] (sum) {};
  \node[sum, right of = sum] (s2) {};
  \node[block, right of = s2, font = \scriptsize] (G) {$\frac{K}{Js + a}$};
  \node[block, right of = G, font = \scriptsize] (H) {$\frac{1}{s}$};
  \node[block, below of = G, font = \scriptsize] (F) {$K_f$};

  \draw[-latex] (G) -- node[name = u] {} (H);
  \draw[-latex] (u) |- (F);
  \draw[-latex] (F) -| node[pos = 0.99] {$-$} node[pos = 1.105] {$+$} (s2);

  \node[output, right of = H] (Y) {};

  \draw[-latex] (input) -- node[font = \scriptsize] {$X$} (sum);
  \draw[-latex] (sum) -- (s2);
  \draw[-latex] (s2) -- (G);

  \coordinate[below of = F, name = empty] {}; 

  \draw[-latex] (H) -- node[name = Y, font = \scriptsize] {$Y$} (Y);
  \draw (Y) |- (empty);
  \draw[-latex] (empty) -| node[pos = 0.99] {$-$} node[pos = 1.05] {$+$} (sum);
\end{tikzpicture}
\end{document}

The code above produces

enter image description here

  1. I would like to decrease the distance between the feedback loop and K_f since there is a lot of wasted space.
  2. How can I center block G between s2 and H?
dustin
  • 18,617
  • 23
  • 99
  • 204

4 Answers4

7

For 1., you have to place th empty coordinate properly. Replace

\coordinate[below of = F, name = empty] {};

with

\coordinate[below  = 0.2cm of F, name = empty] {};

Change 0.2cm appropriately. Also use positioning library and use = of syntax than of = for positioning. This solves your second question.

\documentclass[tikz, convert = false,border=10pt]{standalone}

\usepackage[utf8]{inputenx}%  http://ctan.org/pkg/inputenx
% Euler for math | Palatino for rm | Helvetica for ss | Courier for tt
\renewcommand{\rmdefault}{ppl}% rm
\linespread{1.05}% Palatino needs more leading
\usepackage[scaled]{helvet}% ss //  http://ctan.org/pkg/helvet
\usepackage{courier}% tt // http://ctan.org/pkg/courier
\usepackage{eulervm}  %  http://ctan.org/pkg/eulervm
% a better implementation of the euler package (not in gwTeX)
\normalfont%
\usepackage[T1]{fontenc}%  http://ctan.org/pkg/fontenc
\usepackage{textcomp}%  http://ctan.org/pkg/textcomp

\usetikzlibrary{shapes, arrows,positioning}

\begin{document}
\tikzset{block/.style = {draw, rectangle, minimum height = 2em, minimum width = 3em},
         sum/.style = {draw, circle},
         input/.style = {coordinate},
         output/.style = {coordinate}
}

\begin{tikzpicture}[auto, node distance = 2cm]
  \node[input, name = input] {};
  \node[sum, right = of input] (sum) {};
  \node[sum, right  = of sum] (s2) {};
  \node[block, right = of s2, font = \scriptsize] (G) {$\frac{K}{Js + a}$};
  \node[block, right = of G, font = \scriptsize] (H) {$\frac{1}{s}$};
  \node[block, below = of G, font = \scriptsize] (F) {$K_f$};

  \draw[-latex] (G) -- node[name = u] {} (H);
  \draw[-latex] (u) |- (F);
  \draw[-latex] (F) -| node[pos = 0.99] {$-$} node[pos = 1.105] {$+$} (s2);

  \node[output, right  = of H] (Y) {};

  \draw[-latex] (input) -- node[font = \scriptsize] {$X$} (sum);
  \draw[-latex] (sum) -- (s2);
  \draw[-latex] (s2) -- (G);

  \coordinate[below  = 0.2cm of F, name = empty] {};

  \draw[-latex] (H) -- node[name = Y, font = \scriptsize] {$Y$} (Y);
  \draw (Y) |- (empty);
  \draw[-latex] (empty) -| node[pos = 0.99] {$-$} node[pos = 1.08] {$+$} (sum);
\end{tikzpicture}
\end{document}

enter image description here

2

A (not very elegant) PSTricks solution:

\documentclass{article}

\usepackage{pstricks-add}


\begin{document}

\begin{pspicture}(8.5,2.5)
\psset{unit = 0.5, linecap = 1}
  \pnodes{P}(0,4)(3,4)(6,4)(9,4)(11,4)(13,4)(15,4)(17,4)(15,0)(3,0)(11,1.5)(9,1.5)(6,1.5)
  \pscircle(P1){0.3}
  \uput[135](P1){$+$}
  \uput[225](P1){$-$}
  \pscircle(P2){0.3}
  \uput[135](P2){$+$}
  \uput[225](P2){$-$}
  \pcline[linestyle = none, offset = 9pt](P0)(P1)
  \ncput{$X$}
  \ncline[linecap = 2, nodesep = 4pt]{->}{P0}{P1}
  \ncline[nodesep = 4pt]{->}{P1}{P2}
  \ncline[nodesepA = 4pt, nodesepB = 14.5pt]{->}{P2}{P3}
  \rput(P3){\psframebox{$\frac{K}{Js + a}$}}
  \ncline[nodesepA = 14.5pt, nodesepB = 7pt]{->}{P3}{P5}
  \rput(P5){\psframebox{$\frac{1}{s}$}}
  \ncline[nodesepA = 7pt]{->}{P5}{P7}
  \uput[90](P6){$Y$}
  \psline(P6)(P8)(P9)
  \ncline[nodesepB = 4pt]{->}{P9}{P1}
  \psline(P4)(P10)
  \ncline[nodesepB = 10.5pt]{->}{P10}{P11}
  \rput(P11){\psframebox{$K_{f}$}}
  \ncline[nodesepA = 10.5pt]{P11}{P12}
  \ncline[nodesepB = 4pt]{->}{P12}{P2}
\end{pspicture}

\end{document}

output

2

You can also use the schemabloc package it can describe more compactly the block diagrams. It is also highly configurable.

But it is described in French.

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{calc}

\usepackage{schemabloc}


\begin{document}

\begin{tikzpicture}
\sbEntree{X} 
\sbComp*{C1}{X}     \sbRelier[X]{X}{C1}
\sbComp{C2}{C1}     \sbRelier{C1}{C2}
\sbBlocL{F}{$\frac{K}{J\cdot s+a}$}{C2}
\sbBlocL[6]{int}{$\frac{1}{s}$}{F}
\sbSortie[6]{Y}{int}        \sbRelier[Y]{int}{Y}

\sbDecaleNoeudy{F}{R}
\sbBlocr[-2]{R}{$K_f$}{R}   \sbRelieryx{F-int}{R}
\sbRelierxy{R}{C2}
\sbRenvoi[6]{int-Y}{C1}{text}
\end{tikzpicture}
\end{document}

output1

Another style:

\begin{tikzpicture}
\sbEntree{X} 
\sbComph*{C1}{X}        \sbRelier[X]{X}{C1}
\sbComp*{C2}{C1}        \sbRelier{C1}{C2}
\sbBlocL{F}{$\frac{K}{J\cdot s+a}$}{C2}
{
\sbStyleBloc{fill=yellow!30,text=blue,align=center}
\sbBlocL[6]{int}{$\frac{1}{s}$}{F}
}
\sbSortie[6]{Y}{int}        \sbRelier[Y]{int}{Y}

\sbDecaleNoeudy{F}{R}
{\sbStyleBloc{fill=red!30,text=purple,align=center}
\sbBlocr[-2]{R}{$K_f$}{R}   
}
\sbRelieryx{F-int}{R}
\sbRelierxy{R}{C2}
\sbRenvoi[-4]{int-Y-1}{C1}{text}
\end{tikzpicture}

output2

rpapa
  • 12,350
1

With this kind of schemas which present such a regular distribution a matrix node is helpful.

You define column sep and row sep which means the space between node borders. And write your nodes like in a tabular or array (except for \\ after very last row). If you need to change the distance between two particular columns use &[distance increment] instead of just & and use \\[row increment] to change distance between two particular rows.

\documentclass[tikz, convert = false,border=10pt]{standalone}

\usepackage[utf8]{inputenx}%  http://ctan.org/pkg/inputenx
% Euler for math | Palatino for rm | Helvetica for ss | Courier for tt
\renewcommand{\rmdefault}{ppl}% rm
\linespread{1.05}% Palatino needs more leading
\usepackage[scaled]{helvet}% ss //  http://ctan.org/pkg/helvet
\usepackage{courier}% tt // http://ctan.org/pkg/courier
\usepackage{eulervm}  %  http://ctan.org/pkg/eulervm
% a better implementation of the euler package (not in gwTeX)
\normalfont%
\usepackage[T1]{fontenc}%  http://ctan.org/pkg/fontenc
\usepackage{textcomp}%  http://ctan.org/pkg/textcomp

\usetikzlibrary{shapes, arrows,positioning}

\begin{document}
\tikzset{block/.style = {draw, rectangle, minimum height = 2em, minimum width = 3em},
         sum/.style = {draw, circle, label={[font=\scriptsize, inner sep=0pt]135:$+$},label={[font=\scriptsize, inner sep=0pt]225:$-$}},
         input/.style = {coordinate},
         output/.style = {coordinate},
       aux/.style = {coordinate}
}

\begin{tikzpicture}[auto, node distance = 2cm]
    \matrix (schema) [column sep=0.5cm, row sep=0.5cm]
    { \node[input, name = input] {}; 
            &[0.5cm] \node[sum] (sum) {}; 
            & \node[sum] (s2) {};
            & \node[block, font = \scriptsize] (G) {$\frac{K}{Js + a}$}; 
            &\node[aux] (GH) {};
            &\node[block, font = \scriptsize] (H) {$\frac{1}{s}$};
            &\node[aux] (HY) {};
          &\node[output] (Y) {}; \\
            & 
            &
            & \node[block, font = \scriptsize] (F) {$K_f$};
            & & & \\
            & \node[aux] (fb1) {}; & & & \node[aux] (fb2) {}; \\};

\draw[-latex] (input) -- node[above,font=\scriptsize]{$X$} (sum);
\draw[-latex] (sum) -- (s2);
\draw[-latex] (s2) -- (G);
\draw[-latex] (G) -- (H);
\draw[-latex] (H)--node[above,font=\scriptsize] {$Y$} (Y);

\draw[-latex] (GH)|- (F);
\draw[-latex] (F)-|(s2);

\draw[-latex] (HY)|- (fb1)--(sum);

\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588