
\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}
答え1
left of=measurements
に置き換えますbelow=of controller
。
3 つの小さな注意点:
left of
、 etcキーright of
は非推奨です。etcleft=of ...
の代わりにを使用することが推奨されます。left of=...
これには が必要です\usetikzlibrary{positioning}
。この変更は単なる文字の転置ではありません。新しい配置は、以前の方法よりも堅牢で柔軟性があります。の代わりに
block/.style = {...}
( のオプションとして、tikzpicture
または の引数として)と書くことができます。私の理解では、最初の方法 (以下でも使用) の方が現在の tikz の規則に沿っています。2 番目の方法は、tikz の他の場所では使用されていない、かなり特異な構文です。\tikzset
\tikzstyle{block} = [...]
Zarko がコメントで指摘しているように、ノード距離は、例えば を指定することによって x 方向と y 方向で別々に選択できます
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}
答え2
補足としてゲルノット(それほど)「冗長な」回答ではありませんが、より簡潔になれば幸いです:) その中で私はライブラリcalc
を使用しますquotes
:
\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}
編集:変更を考慮してカーラテックスコメント、コード内のコメントはより意味のあるものになりました。私が提案したブロック「センサー」と「測定」の順序は正しいと今でも信じています。ただし、これらのブロックが線形になるまでは、順序は重要ではありません :)
答え3
TikZ も使用できると思いますmatrix
。
このライブラリは非推奨であることに注意してくださいarrows
。TikZ & PGF マニュアル、パラグラフ 16.1 より:
注意: ライブラリ arrows と arrows.spaced は非推奨です。代わりに/追加で arrows.meta を使用すると、古いライブラリで提供されていたすべての機能に加え、さらに多くの機能を使用できます。ただし、古いライブラリは引き続き機能し、古い矢印の先端と新しい矢印の先端を混在させることもできます (ただし、古い矢印の先端は、このセクションの残りの部分で説明されている方法で構成することはできません。たとえば、LaTex 矢印に scale=2 を指定しても効果はありませんが、LaTex 矢印の場合は、予想どおりにサイズが 2 倍になります)。
さらに、gernotがすでに述べたように、(参照)\tikzset
の代わりに使用する必要があります。\tikzstyle
ここ)。
\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}