\tikzstyle{block} = [draw, fill=blue!20, rectangle,
minimum height=3em, minimum width=6em]
\tikzstyle{sum} = [draw, fill=blue!20, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
% The block diagram code is probably more verbose than necessary
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
% We start by placing the blocks
\node [input, name=input] {};
\node [sum, right of=input] (sum) {};
\node [block, right of=sum] (controller) {Controller};
\node [block, right of=controller, pin={[pinstyle]above:Disturbances},
node distance=3cm] (system) {System};
% 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] {$u$} (system);
\node [output, right of=system] (output) {};
\node [block, below of=system] (measurements) {Measurements};
\node [block, left of=measurements ] (sensor) {Sensor};
\draw [<-] (measurements) -- node[name=k] {$k$} (sensor);
% Once the nodes are placed, connecting them is easy.
\draw [draw,->] (input) -- node {$r$} (sum);
\draw [->] (sum) -- node {$e$} (controller);
\draw [->] (system) -- node [name=y] {$y$}(output);
\draw [->] (y) |- (measurements);
\draw [->] (sensor) -| node[pos=0.99] {$-$}
node [near end] {$y_m$} (sum);
\end{tikzpicture}
- 62,716
3 Answers
Replace left of=measurements by below=of controller.
Three minor notes:
The
left of,right ofetc keys are deprecated. It is now recommended to useleft=of ...instead ofleft of=...etc. This requires\usetikzlibrary{positioning}. This change is more than a transposition of letters. The new positioning is more robust and flexible than the old way.You can write
block/.style = {...}(as an option totikzpictureor as an argument to\tikzset) instead of\tikzstyle{block} = [...]. As I understand it, the first method (that I also used below) is more in line with the current tikz conventions. The second method is a rather singular syntax not used elsewhere in tikz.As Zarko has noted in the comments, the node distance can be chosen differently in the x and y direction by specifying e.g.
node distance=1cm and 2cm.
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}
\tikzset
{block/.style =
{draw, fill=blue!20, rectangle, minimum height=3em, minimum width=6em},
sum/.style = {draw, fill=blue!20, circle, node distance=1cm},
input/.style = {coordinate},
output/.style = {coordinate},
pinstyle/.style = {pin edge={to-,thin,black}}
}
\begin{document}
% The block diagram code is probably more verbose than necessary
\begin{tikzpicture}[auto, node distance=1cm and 2cm,>=latex']
% We start by placing the blocks
\node [input, name=input] {};
\node [sum, right=of input] (sum) {};
\node [block, right=of sum] (controller) {Controller};
\node [block, right=of controller, pin={[pinstyle]above:Disturbances},
node distance=3cm] (system) {System};
% 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] {$u$} (system);
\node [output, right=of system] (output) {};
\node [block, below=of system] (measurements) {Measurements};
\node [block, below=of controller] (sensor) {Sensor};
\draw [<-] (measurements) -- node[name=k] {$k$} (sensor);
% Once the nodes are placed, connecting them is easy.
\draw [draw,->] (input) -- node {$r$} (sum);
\draw [->] (sum) -- node {$e$} (controller);
\draw [->] (system) -- node [name=y] {$y$}(output);
\draw [->] (y) |- (measurements);
\draw [->] (sensor) -| node[pos=0.99] {$-$}
node [near end] {$y_m$} (sum);
\end{tikzpicture}
\end{document}
- 49,614
-
probably is right
\draw [->] (measurements) -- node[name=k] {$k$} (sensor);:) and for node distance I would make different vertical and horizontal distance, for examplenode distance=1cm and 2cm... – Zarko Apr 27 '17 at 08:25 -
@Zarko Changing the node distance is a good idea. Regarding the arrow: My first idea was also to change its direction, but I think the arrows are correct as they are, since sensors usually only deliver data, but do not receive them. – gernot Apr 27 '17 at 08:58
-
well observation, but this means that (as far s know from control theory) that sensor and measurement block had to be interchanged ... – Zarko Apr 27 '17 at 09:03
-
-
As supplement to gernot (no so much) "verbose" answer, hopefully it is more concise :) In it I use calc and quotes library:
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, calc, positioning, quotes}
\tikzset{
block/.style = {rectangle, draw, fill=blue!20, minimum height=3em, minimum width=6em},
sum/.style = {circle, draw, fill=blue!20},
every pin/.style = {pin edge={<-,black}},
> = latex'
}
\begin{document}
\begin{tikzpicture}[auto,
node distance = 6mm and 12mm]
% placing the blocks
\coordinate (in);
\node (sum) [sum, right=of in] {};
\node (controller) [block, right=of sum] {Controller};
\node (system) [block, pin=above:Disturbances,
right=of controller] {System};
\coordinate[right=of system] (out);
\node (measurement) [block, below=of controller] {Measurements};
\node (sensor) [block, below=of system] {Sensor};
% edges between blocks
\draw[->] (in) edge ["$r$"] (sum)
(sum) edge ["$e$"] (controller)
(controller) edge["$u$"] (system)
(system) edge["$y$"] (out)
(sensor) edge["$k$"] (measurement)
(measurement) -| (sum)
node [pos=0.75] {$y_m$}
node [pos=0.95] {$-$};
\draw[->] ($(system.east)!0.5!(out)$) |- (sensor);
\end{tikzpicture}
\end{document}
Edit: Change considering CarLaTeX comment, comments in code are now more meaningful. I still believe, that my suggested order of blocks "sensor"and "measuremnt" are correct. However until these blocks are linear, the order is not esential :)
- 296,517
-
@CarLaTeX, as *Gernot" said, we help to solve LaTeX issues :). Order become important when blocks are not linear. Hopefully OP know, what is correct to her/him and that change of blocks name after received three answers is not problem (anymore) :) – Zarko Apr 27 '17 at 13:38
-
Yes, of course! It's trivial to change the position of the node... I wrote it only because I was already writing about the arrow :):):) This OP is lucky with 3 answers! – CarLaTeX Apr 27 '17 at 13:47
I think you could also use a TikZ matrix.
Please note that arrows library is deprecated. From the TikZ & PGF 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. However, the old libraries still work and you can even mix old and new arrow tips (only, the old arrow tips cannot be configured in the ways described in the rest of this section; saying scale=2 for a latex arrow has no effect for instance, while for Latex arrows it doubles their size as one would expect.)
Moreover, as gernot already said, \tikzset should be used instead of \tikzstyle (see here).
\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,matrix,positioning}
\begin{document}
\tikzset{%
block/.style={draw, fill=blue!20, rectangle,
minimum height=3em, text width=7em,align=center},
sum/.style={draw, fill=blue!20, circle},
pinstyle/.style={pin edge={latex-,thin,black}},
mylabup/.style={midway,above},
>=latex,
}
\begin{tikzpicture}
\matrix[column sep=3em, row sep=4ex]{%
\coordinate (input);
&
\node [sum] (sum) {};
&
\node [block] (controller) {Controller};
&
\node [block, pin={[pinstyle]above:Disturbances}] (system) {System};
&
\coordinate (output);
\\
&
&
\node [block] (sensor) {Sensor};
&
\node [block] (measurements) {Measurements};
\\
};
\draw [->] (controller) -- node[mylabup] {$u$} (system);
\draw [->] (measurements) -- node[mylabup] {$k$} (sensor);
\draw [->] (input) -- node[mylabup] {$r$} (sum);
\draw [->] (sum) -- node[mylabup] {$e$} (controller);
\draw [->] (system) -- node [name=y,mylabup] {$y$} (output);
\draw [->] (y) |- (measurements);
\draw [->] (sensor) -|
node [near end, left] {$y_m$} (sum);
\node[below left = -2pt and -1pt of sum] {$-$};
\end{tikzpicture}
\end{document}
- 62,716




positioningandleft=1cm of measurements, which will let you adjust the distance. – TeXnician Apr 27 '17 at 05:09