我正在尝试重新创建该图表:
Environment
我的已经看起来相当不错了,但是和节点之间的连接Sensor
缺少第二个直角和measured by
文本的空间。
如何为节点添加必要的空间?
tikz
另外,是否可以从外部文件加载图表?
这是 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}