다른 노드를 기준으로 \draw 명령에서 노드 선언

다른 노드를 기준으로 \draw 명령에서 노드 선언

주석 처리된 줄이 작동하지 않는 이유는 무엇입니까? \draw 명령에 선언된 노드(실제로는 익명 노드)를 배치하고 싶습니다.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}
\begin{document}
\title{arrow test}
\begin{tikzpicture}[>=latex,
  font=\sffamily,
]

\node[draw, thin, black, fill=green, rectangle] (P1) at (0cm,0cm){};
\node[draw, thin, black, fill=red, rectangle, right=1cm of P1] (P2){};
\node[draw, thin, black, fill=green, rectangle] (P3) at (0cm,0.5cm){};
\draw[->] (P1) -- (P2);
%\draw[->] (P3) to node[draw, thin, black, fill=red, rectangle, right=1cm of P3](P4){};
\end{tikzpicture}
\end{document}

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

답변1

다음 MWE를 시도해 보십시오.

\documentclass[tikz, border=3mm]{standalone}
\usetikzlibrary{positioning}

\begin{document}
\title{arrow test}
\begin{tikzpicture}[%>=latex,
    node distance = 10mm,
box/.style = {rectangle, draw, thin, fill=#1, font=\sffamily},
                    ]
\node[box=green]            (P1) at (0cm,0cm)  {};
\node[box=red, right=of P1] (P2)    {};
\node[box=green]            (P3) at (0cm,1cm)   {};

\draw[->] (P1) -- (P2);
\draw[->] (P3) node[box=red, right=of P3] (P4) {} -- (P4);
\end{tikzpicture}
\end{document}

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

좌표는 "부트스트랩"될 수 없습니다. 먼저 좌표를 정의한 후 사용하세요. 귀하와 내 MWE의 마지막 줄을 비교하십시오.

답변2

이것은 거의 원하는 것입니다. 첫 번째 노드의 중심에서 1cm 거리가 계산된다는 결함이 있습니다(따라서 이 예에서는 두 개의 오른쪽 노드가 올바르게 정렬되지 않았습니다).

 \documentclass[border=3mm]{standalone}
 \usepackage{tikz}
 \usetikzlibrary{positioning, calc}
 \begin{document}
 \title{arrow test}
 \begin{tikzpicture}[>=latex,
   font=\sffamily,
 ]

 \node[draw, thin, black, fill=green, rectangle] (P1) at (0cm,0cm){};
 \node[draw, thin, black, fill=red, rectangle, right=1cm of P1] (P2){};
 \node[draw, thin, black, fill=green,opacity=0.5, rectangle] (P3) at (0cm,0.5cm){};
 \draw[->] (P1) -- (P2);
 \draw[->] (P3) -- +(1cm,0)  node[draw, thin, black, fill=red, rectangle, right] (P4) {};

 % \draw[->] (0,0.5cm) node[draw, thin, black, fill=green,opacity=0.5,
 % rectangle,left] {} -- +(1cm,0) node[draw, thin, black, fill=red, rectangle,
 % right] {};
 \end{tikzpicture}
 \end{document}

따라서 어떤 의미에서는 익명 노드를 그리는 것이 가능합니다. 문제는 연속 경로의 시작점을 변경해야 하기 때문에 두 노드에 대해서만 작동한다는 것입니다. 이는 노드가 익명인 경우 불가능합니다.

관련 정보