`\node`와 `\coordinate` 구현의 차이점이 표시됩니다.

`\node`와 `\coordinate` 구현의 차이점이 표시됩니다.

TikZ두 개의 평행선 세그먼트를 그릴 수 있는 네 가지 환경은 다음과 같습니다 . 모든 환경에서 첫 번째 선분의 한 끝점은 또는 로 지정되고 \coordinate(A), \node(A){$A$};두 번째 선분의 한 끝점은 \coordinate(B)또는 로 지정됩니다 \node(B){$B$};.

A 지점이 먼저 지정됩니다. 이에 대한 좌표는 제공되지 않습니다. TikZ기본적으로 원점에 배치되나요 ? 두 번째 그래프에는 명령이 있고 \node at (0,0) {$O$};"O"가 A의 좌표에 조판되어 있기 때문에 원점에 배치된 것 같습니다 .

"A" 위치를 제외하면 두 번째와 세 번째 디스플레이는 동일합니다. 두 번째 디스플레이에서는 \coordinate(A);및 를 사용하여 \node at (0,0) {$A$};"A" 위치를 지정하고, 세 번째 디스플레이에서는 \node[inner sep=0pt,outer sep=0pt] (A){$A$};"A" 위치를 지정합니다. 두 번째 디스플레이에서는 "A"가 (0,0) 중앙에 있는 것처럼 보이고, 세 번째 디스플레이에서는 "A"가 (0,0) 왼쪽에 조판된 것 같습니다. 왜 차이가 있나요?

세 번째 및 네 번째 디스플레이에 대한 코딩의 유일한 차이점은 inner sep=0pt세 번째 디스플레이에서 "A"를 조판하기 위한 node 명령의 옵션과 inner sep=1.5pt네 번째 디스플레이에서 "A"를 조판하기 위한 node 명령의 옵션이 있다는 것입니다. 이것이 세 번째 디스플레이와 비교하여 네 번째 디스플레이의 "모든 것"을 이동시키는 이유는 무엇입니까?

\documentclass{amsart}
\usepackage{tikz}\usetikzlibrary{calc,positioning}
\begin{document}

    \begin{tikzpicture}
    \coordinate(A);
    \coordinate[right=of A](B);
    \draw[yellow, line width=2pt] (A) -- ++(1,1);
    \draw[red] (B) -- ++(1,1);
    \end{tikzpicture}
    \vskip1.25mm

    \begin{tikzpicture}
    \coordinate(A);
    \coordinate[right=of A](B);
    \draw[yellow, line width=2pt] (A) -- ++(1,1);
    \draw[red] (B) -- ++(1,1);
    \node at (0,0) {$A$};
    \end{tikzpicture}
    \vskip1.25mm

    \begin{tikzpicture}
    \node[inner sep=0pt,outer sep=0pt] (A){$A$};
    \coordinate[right=of A](B);
    \draw[yellow, line width=2pt] (A) -- ++(1,1);
    \draw[red] (B) -- ++(1,1);
    \end{tikzpicture}
    \vskip1.25mm

    \begin{tikzpicture}
    \node[inner sep=1.5pt,outer sep=0pt] (A) {$A$};
    \coordinate[right=of A] (B);
    \draw[yellow, line width=2pt] (A) -- ++(1,1);
    \draw[red] (B) -- ++(1,1);
    \end{tikzpicture}

\end{document}

답변1

다음이 도움이 됩니까?

\documentclass[tikz,border=5pt,mult]{standalone}
\usetikzlibrary{positioning}

\begin{document}

  \begin{tikzpicture}[every node/.style={draw}]
    \draw [help lines] (-1,-1) grid (2,2);
    \coordinate(A);
    \coordinate[right=of A](B);
    \draw [blue] (A) -- ++(1,1);
    \draw (B) -- ++(1,1);
    \node at (0,0) {$A$};
    \path [fill=blue] (0,0) circle (1.5pt);
  \end{tikzpicture}

  \begin{tikzpicture}[every node/.style=draw]
    \draw [help lines] (-1,-1) grid (2,2);
    \node[inner sep=0pt,outer sep=0pt] (A){$A$};
    \coordinate[right=of A](B);
    \draw [blue] (A) -- ++(1,1);
    \draw (B) -- ++(1,1);
    \path [fill=blue] (0,0) circle (1.5pt);
  \end{tikzpicture}

\end{document}

사례 1

첫 번째 경우 파란색 선은 좌표에서 그려지고 AB좌표를 기준으로 배치됩니다. 좌표는 점이므로 이는 에서 그리는 것과 같습니다 (0,0).

사례 2

두 번째 경우에는 파란색 선이 노드 에서 그려지고 A노드 B를 기준으로 위치가 지정됩니다. TikZ는 노드 경계의 가장 가까운 지점에서 그리거나 측정한다고 가정합니다. A0 inner sep과 가 있더라도 공간을 차지하는 outer sep문자가 포함되어 있으므로 여전히 양수 크기를 갖습니다 . A따라서 이 경우 선은 의 약간 위쪽, 약간 오른쪽에 그려 (0,0)지고 B의 약간 오른쪽에 있는 점을 기준으로 배치됩니다 (0,0).

앵커 를 지정하여 좌표 사용 효과를 에뮬레이트할 수 있습니다 center.

  \begin{tikzpicture}[every node/.style=draw]
    \draw [help lines] (-1,-1) grid (2,2);
    \node[inner sep=0pt,outer sep=0pt] (A){$A$};
    \coordinate[right=of A.center](B);
    \draw [blue] (A.center) -- ++(1,1);
    \draw (B) -- ++(1,1);
    \path [fill=blue] (0,0) circle (1.5pt);
  \end{tikzpicture}

앵커를 사용하여 좌표를 에뮬레이션

또는 노드에 A내용이 없고 zero 도 없으면 sep본질적으로 공간을 차지하지 않기 때문에 좌표와 유사하게 작동합니다.

  \begin{tikzpicture}[every node/.style=draw]
    \draw [help lines] (-1,-1) grid (2,2);
    \node[inner sep=0pt,outer sep=0pt] (A){};
    \coordinate[right=of A](B);
    \draw [blue] (A) -- ++(1,1);
    \draw (B) -- ++(1,1);
    \node at (A) {$A$};
    \path [fill=blue] (0,0) circle (1.5pt);
  \end{tikzpicture}

빈 노드를 사용하여 좌표를 에뮬레이션

모든 경우에 는 원점 (파란색 점으로 표시)의 A중심에 있습니다 .(0,0)

관련 정보