tikz에서 상대적으로 위치를 지정하는 방법은 무엇입니까?

tikz에서 상대적으로 위치를 지정하는 방법은 무엇입니까?

tikz를 사용하여 제어 다이어그램을 그리려고 하는데 이에 관해 몇 가지 질문이 있습니다.

  • 교란으로부터 경계를 어떻게 제거할 수 있습니까?
  • 비용 및 제약 조건 노드를 왼쪽 및 오른쪽 위치에 어떻게 배치할 수 있습니까?

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

\tikzstyle{controller} = [draw, fill=blue!20, rectangle, 
minimum height=3em, minimum width=6em]
\tikzstyle{block} = [draw, fill=yellow!20, rectangle, 
minimum height=3em, minimum width=6em]

\tikzstyle{disturbance} = [draw, node distance=1.5cm, line width=0pt]    
\tikzstyle{sum} = [draw, circle, node distance=1.5cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\begin{figure}[!]
\centering
\begin{tikzpicture}[auto, node distance=3cm,>=latex', scale=0.5 ,every
node/.style={transform shape}]      
    % We start by placing the blocks
    \node [input, name=input] {};
    \node [sum, right of=input] (sum) {};
    \node [controller, right of=sum] (controller) {Controller};
    \node [block, right of=controller, node distance=4cm] (system) {System};
    \node [disturbance, name=disturbance, above of=system] {Disturbance};
    \node [disturbance, name=costfunc, below of=system,] {Cost};
    \node [disturbance, name=constraint, below of=system] {Constraints};
    % 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(n)$} (system);
    \node [output, right of=system] (output) {};        

    % Once the nodes are placed, connecting them is easy. 
    \draw [draw,->] (input) -- node {$r(n)$} (sum);
    \draw [->] (sum) -- node {$e(n)$} (controller);
    \draw [->] (disturbance) -- (system);
    \draw [->] (system) -- node [name=y] {$y(n)$}(output);
    \draw [->] (y) |-  ($(y.south) + (0,-2)$) -| node[pos=0.99]
    {$-$} node [near end] {$y(n)$} (sum);
\end{tikzpicture}   
\label{fig:mpc_bloc_diagram}
\end{figure}

편집됨

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

y(n)에 더 가깝게 이동 Predict rectangle하려면 어떻게 해야 합니까?u(n)

위의 결과로 다음을 시도했습니다.

\draw [->] (y) |- node [near end] {$y(n)$} ($(predict.east)+(0,0.35)$);
\draw [->] (u) |- node [near end] {$u(n)$} ($(predict.east)+(0,-0.35)$);

답변1

  1. draw=none. 아니면 테두리를 그리지 않고 새 노드 스타일을 정의하시겠습니까?

  2. 원하는 결과에 따라 여기에는 많은 가능성이 있습니다. 예를 들어 앵커, 교대를 사용하여 위치 조정을 미세 조정할 수 below right있습니다 . 라이브러리가 로드된 below left경우 positioning다음과 같은 것을 사용할 수 있습니다 below left=10pt and 20pt of <name>(아래 두 번째 예제 코드 참조).

코드:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}

\begin{document}

\tikzstyle{controller} = [draw, fill=blue!20, rectangle, 
minimum height=3em, minimum width=6em]
\tikzstyle{block} = [draw, fill=yellow!20, rectangle, 
minimum height=3em, minimum width=6em]

\tikzstyle{disturbance} = [draw, node distance=1.5cm, line width=0pt]    
\tikzstyle{sum} = [draw, circle, node distance=1.5cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\begin{figure}
\centering
\begin{tikzpicture}[auto, node distance=3cm,>=latex', scale=1.5 ,every
node/.style={transform shape}]      
    % We start by placing the blocks
    \node [input, name=input] {};
    \node [sum, right of=input] (sum) {};
    \node [controller, right of=sum] (controller) {Controller};
    \node [block, right of=controller, node distance=4cm] (system) {System};
    \node [disturbance, draw=none,name=disturbance, above of=system] {Disturbance};
    \node [disturbance, name=costfunc, below left of=system,] {Cost};
    \node [disturbance, name=constraint, below right of=system] {Constraints};
    % 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(n)$} (system);
    \node [output, right of=system] (output) {};        

    % Once the nodes are placed, connecting them is easy. 
    \draw [draw,->] (input) -- node {$r(n)$} (sum);
    \draw [->] (sum) -- node {$e(n)$} (controller);
    \draw [->] (disturbance) -- (system);
    \draw [->] (system) -- node [name=y] {$y(n)$}(output);
    \draw [->] (y) |-  ($(y.south) + (0,-2)$) -| node[pos=0.99]
    {$-$} node [near end] {$y(n)$} (sum);
\end{tikzpicture}   
\label{fig:mpc_bloc_diagram}
\end{figure}

\end{document}

솜 발언:

  1. 도서관 이용 of=으로 변경해주세요 .=ofpositioning

  2. \tikzstyle에서 로 변경하세요 \tikzset.

  3. figureinside 와 같은 플로트를 배치할 수 없습니다 tikzpicture. 다른 곳에서도 할 수 있어요.

  4. 배율 인수가 약간 낮은 것 같습니다.

코드:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows,positioning}

\tikzset{
controller/.style={
  draw, 
  fill=blue!20, 
  rectangle, 
  minimum height=3em, 
  minimum width=6em
  },
block/.style={
  draw, 
  fill=yellow!20, 
  rectangle, 
  minimum height=3em, 
  minimum width=6em
  },
disturbance/.style={
  draw, 
  line width=0pt
  },    
sum/.style={
  draw, 
  circle, 
  node distance=1.5cm
  },
input/.style={coordinate},
output/.style={coordinate}
}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[
  auto, 
  node distance=1.5cm,
  >=latex', 
  scale=0.5 ,
  every node/.style={transform shape}
]      
    % We start by placing the blocks
    \node [input, name=input] {};
    \node [sum, right =of input] (sum) {};
    \node [controller, right =of sum] (controller) {Controller};
    \node [block, right =of controller, node distance=4cm] (system) {System};
    \node [disturbance, draw=none,name=disturbance, above = 20pt of system] {Disturbance};
    \node [disturbance,draw=none,name=costfunc, below left = 20pt and 0pt of system,anchor=east] {Cost};
    \node [disturbance,draw=none,name=constraint, below right = 20pt and 15pt of system,anchor=east] {Constraints};
    % 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(n)$} (system);
    \node [output, right =of system] (output) {};        

    % Once the nodes are placed, connecting them is easy. 
    \draw [draw,->] (input) -- node {$r(n)$} (sum);
    \draw [->] (sum) -- node {$e(n)$} (controller);
    \draw [->] (disturbance) -- (disturbance|-system.north);
    \draw [->] (system) -- node [name=y] {$y(n)$}(output);
    \draw [->] (y) |-  ($(y.south) + (0,-2)$) -| node[pos=0.99]
    {$-$} node [near end] {$y(n)$} (sum);
\end{tikzpicture}   
\label{fig:mpc_bloc_diagram}
\end{figure}

\end{document}

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

원래 질문을 편집한 후 새 질문의 경우 첫 번째 레이블의 노드 중 하나에 이름을 지정한 다음 수직 좌표계를 사용하여 다른 레이블을 동일한 x 좌표에 배치하는 것이 아이디어입니다. 다음 예제 코드는 이를 보여줍니다.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows,positioning}

\tikzset{
controller/.style={
  draw, 
  fill=blue!20, 
  rectangle, 
  minimum height=3em, 
  minimum width=6em
  },
block/.style={
  draw, 
  fill=yellow!20, 
  rectangle, 
  minimum height=3em, 
  minimum width=6em
  },
disturbance/.style={
  draw, 
  line width=0pt
  },    
sum/.style={
  draw, 
  circle, 
  node distance=1.5cm
  },
input/.style={coordinate},
output/.style={coordinate}
}

\begin{document}

\begin{tikzpicture}[
  auto, 
  node distance=1.5cm,
  >=latex', 
  every node/.style={transform shape}
]      
  \node [controller] (nodea) {Some node a};
  \node [controller, right =of nodea] (nodeb) {Some node b};
  \node [controller, above left =of nodea] (nodec) {Some node c};

  \draw [->] 
    (nodea) |- 
      node [near end] (un) {$u(n)$}
  ($(nodec.east)+(0,-0.35)$);
  \draw [->] 
    (nodeb) |- 
      coordinate[near end] (aux) 
  ($(nodec.east)+(0,0.35)$) node[above] at (un|-aux) {$y(n)$};
\end{tikzpicture}   

\end{document}

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

관련 정보