
この図を再現しようとしています:
Environment
私のものはすでにかなり良さそうですが、ノードとノード間の接続にSensor
2 番目の直角とmeasured by
テキスト用のスペースが欠けています。
ノードに必要なスペースを追加するにはどうすればよいですか?
tikz
また、外部ファイルから -diagramを読み込むことは可能ですか?
これはMWEのコードです(ここで試すことができます)https://www.overleaf.com/3051741jzxtvm#/8435913/)
\documentclass[tikz, border=10pt]{standalone}
\usepackage{verbatim}
\tikzset{
vertex/.style = {
circle,
fill = black,
outer sep = 2pt,
inner sep = 1pt,
}
}
\begin{document}
\begin{tikzpicture}[node distance = 2cm, auto]
[
post/.style={->,shorten >=1pt,semithick}
]
% Nodes
\node[draw] (Sensor) at (2,0) {Sensor};
\node[draw] (Comparator) at (6,0) {Comparator};
\node[draw] (Actuator) at (10,0) {Actuator};
\node[draw] (Feedback) at (13,2) {Feedback};
\node[draw] (Environment) at (6,-2) {Environment};
\node[draw] (Disturbances) at (6,-4) {Disturbances};
\node at (1, 1) {\textbf{ Input}};
\node at (11, 1) {\textbf{ Output}};
\draw[->,draw=red] (Sensor) to node {alerts} (Comparator);
\draw[->,draw=red] (Comparator) to node {drives} (Actuator);
\draw[-, draw=red] (Actuator) -| node[pos=0.25] {affects} (Feedback);
\draw[->, draw=red] (Feedback) |- (Environment);
\draw[->, draw=red] (Environment) -| node {measured by} (Sensor);
\draw[<-,draw=red] (Environment) to node {affect} (Disturbances);
\end{tikzpicture}
\end{document}
答え1
tikzlibrary チェーンと配置を使用する代替手段:
\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{chains,positioning}
\usepackage{verbatim}
\begin{document}
\begin{tikzpicture}[
node distance = 2cm, auto,
start chain = going right,
box/.style = {rectangle, draw, on chain}]
% Nodes
\node[box] (Sensor) {Sensor};
\node[box] (Comparator) {Comparator};
\node[box] (Actuator) {Actuator};
\node[box,above right=of Actuator] (Feedback) {Feedback};
\node[box,below=of Comparator] (Environment) {Environment};
\node[box,below=of Environment] (Disturbances) {Disturbances};
% Lines
\draw[->,draw=red] (Sensor) to node {alerts} (Comparator);
\draw[->,draw=red] (Comparator) to node {drives} (Actuator);
\draw[-, draw=red] (Actuator) -| node[pos=0.25] {affects}
node[pos=0.25,above=1cm] {\textbf{ Output}}
(Feedback);
\draw[->,draw=red] (Feedback) |- (Environment);
\draw[->,draw=red] (Environment) -| ([xshift=-2.4cm] Sensor.west) --
node[above] {measured by}
node[above=1cm] {\textbf{ Input}} (Sensor.west);
\draw[<-,draw=red] (Environment) to node {affect} (Disturbances);
\end{tikzpicture}
\end{document}
答え2
Zarkoのサンプルコードから引用
\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{chains,positioning}
\usepackage{verbatim}
\usepackage{xcolor}
\DefineNamedColor{named}{BrickRed} {cmyk}{0,0.89,0.94,0.28}
\DefineNamedColor{named}{DarkRed} {cmyk}{0.4,0.89,0.94,0.28}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\begin{tikzpicture}[
node distance = 2cm, auto,
start chain = going right,
box/.style = {rectangle, draw, on chain}]
\tikzset{>=latex}
\tikzstyle{nodebox}=[box,draw=none,font=\bf]
\tikzstyle{redline}=[-,BrickRed,draw=BrickRed,ultra thick]
\tikzstyle{redliner}=[redline,->]
\tikzstyle{redlinel}=[redline,<-]
\tikzstyle{darklabel}=[below,DarkRed]
% Nodes
\node[nodebox] (Sensor) {Sensor};
\node[nodebox] (Comparator) {Comparator};
\node[nodebox] (Actuator) {Actuator};
\node[nodebox,above right=of Actuator] (Feedback) {Feedback};
\node[nodebox,below=of Comparator] (Environment) {Environment};
\node[nodebox,below=of Environment] (Disturbances) {Disturbances};
% Lines
\draw[redliner] (Sensor) to node[darklabel] {alerts} (Comparator);
\draw[redliner] (Comparator) to node[darklabel] {drives} (Actuator);
\draw[redline] (Actuator) -| node[darklabel,pos=0.25] {affects}
node[pos=0.25,above=1em,DarkRed,font=\bf] {Output} (Feedback);
\draw[redliner] (Feedback) |- (Environment);
\draw[redliner] (Environment) -| ([xshift=-2.4cm] Sensor.west) --
node[darklabel] {measured by}
node[above=1em,DarkRed,font=\bf] {Input} (Sensor.west);
\draw[redlinel] (Environment) to node[DarkRed] {affect} (Disturbances);
\end{tikzpicture}
\end{document}
答え3
簡単なハックは次のとおりです:
\draw[->, draw=red] (Environment) -| ($(Sensor)+(-3,0)$)
|- node[anchor=south west] {measured by} (Sensor);
\usetikzlibrary{calc}
前文に追加する必要があります。
($(Sensor)+(-3,0)$)
パスに追加の座標を追加します。ノード(-3,0)
からのオフセットです(Sensor)
。
アップデート(Zarko の回答に触発されて)
の代わりに($(Sensor)+(-3,0)$)
を使用できます([xshift=-2.4cm] Sensor.west)
。追加のtikz
-libraries を含める必要はありません。