Tikz 다이어그램: 추가 직각 및 공간

Tikz 다이어그램: 추가 직각 및 공간

이 다이어그램을 다시 만들려고 합니다.

여기에 이미지 설명을 입력하세요

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}

여기에 이미지 설명을 입력하세요

답변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.

여기에 이미지 설명을 입력하세요

관련 정보