Tikz가 내 자식 노드를 회전했습니다.

Tikz가 내 자식 노드를 회전했습니다.

나는 tikz에서 나무를 그리고 있는데, 자식 노드가 회전되어 그 안으로 들어가는 선이 오프셋되어 통과하는 것처럼 보입니다. 예를 들어 이 그림을 참조하세요. 특히 선이 어떻게 중심에서 벗어나 있고 파란색 공을 어떻게 통과하는지 주목하세요..

나는 다음을 사용하여 그림을 그렸습니다.

\includepackage{tikz}
\tikzstyle planar forest=[scale=1, sibling distance=0, level distance=0, semithick]
\tikzstyle planar forest node=[scale=1, shape=circle, semithick, draw]
\tikzstyle b=[style=planar forest node, fill=black]
\tikzstyle bb=[style=planar forest node, fill=blue]

환경을 정의하고 다음을 수행합니다.

\tikz[planar forest] {
\node [b, label=right:] at (0.0, 0.0) {}
child {node [bb, label=right:] at (-0.5, 1.0) {}
}
child {node [b, label=right:] at (0.5, 1.0) {}
}
;

}

실제 그림을 그리는 것입니다. 왜 그렇게 추악해 보이는지 아는 사람 있나요?

답변1

내가 알 수 있는 기본적인 문제는 트리 구조와 모든 노드의 수동 배치를 혼합하고 있다는 것입니다. 그래서 추측을 해야 한다면, 나는 다음과 같이 추측할 것입니다.당신의code --- 공유한 코드와 달리 문제를 재현하는 코드, 그렇지 않은 코드 --- Ti에게 말하고 있는 것입니다.케이Z는 나무가 한 방향으로 자라면서 마치 다른 방향으로 자라는 것처럼 노드의 위치를 ​​수동으로 강제하는 것입니다.

sibling distance트리를 사용한 다음 및 를 모두 0으로 설정하는 것은 의미가 없습니다 level distance. 적어도 나는 단순히 상상력이 부족할 수도 있지만 당신이 이것을 하고 싶은 타당한 이유를 생각할 수 없습니다.

\tikzstyle다음은 더 이상 사용되지 않는 항목을 제거 하고 실제로 트리가 되도록 수정된 트리 버전입니다 .

\tikzset{
  planar forest node/.style={shape=circle, semithick, draw},
  b/.style={style=planar forest node, fill=black},
  bb/.style={style=planar forest node, fill=blue},
}
\tikz {
  \node [b, label=right:A] {}
  child {node [bb, label=right:B]  {}
  }
  child {node [b, label=right:C]  {}
  }
  ;
}

나무

또는 다음을 사용하여 grow=up:

나무 위로

열심히 노력하면 대략적인 결과를 얻을 수 있습니다.

못생긴 나무

level그러나 나는 영점 조정 과 sibling distance설정을 통해 이것을 얻었습니다 yscale=-.75.

\tikz [sibling distance=0, level distance=0, yscale=-.75] {
  \node [b] {}
  child {node [bb] at (-.5,1)  {}
  }
  child {node [b] at (.5,1) {}
  }
  ;
}

이는 확실히 해야 할 일이 아닙니다.

완전성을 위해 다음은 다음과 같습니다 forest.

\begin{forest}
  [, b
    [, bb
    ]
    [, b
    ]
  ]
\end{forest}

훨씬 더 간결한 사양으로 트리를 생성합니다.

숲

전체 코드:

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\begin{document}
\tikzset{
  planar forest node/.style={shape=circle, semithick, draw},
  b/.style={style=planar forest node, fill=black},
  bb/.style={style=planar forest node, fill=blue},
}
\tikz {
  \node [b, label=right:A] {}
  child {node [bb, label=right:B]  {}
  }
  child {node [b, label=right:C]  {}
  }
  ;
}
\tikz [grow=up] {
  \node [b, label=right:A] {}
  child {node [bb, label=right:B]  {}
  }
  child {node [b, label=right:C]  {}
  }
  ;
}
\tikz [sibling distance=0, level distance=0, yscale=-.75] {
  \node [b] {}
  child {node [bb] at (-.5,1)  {}
  }
  child {node [b] at (.5,1) {}
  }
  ;
}
\begin{forest}
  [, b
    [, bb
    ]
    [, b
    ]
  ]
\end{forest}
\end{document}

관련 정보