텍스트 중 하나가 지수(예: )가 포함된 수학 표현식을 사용하기 때문에 레벨 1의 텍스트가 정렬되지 않은 트리(예제 참조)가 있습니다 $\mathtt{int}^2$
. 트리의 동일한 수준에 있는 모든 텍스트를 정렬하는 방법에 대해 알고 계시나요?
\documentclass{book}
\usepackage{tikz}
\begin{document}
{\tiny
\begin{tikzpicture}
\begin{scope}[level distance=6mm]
\tikzstyle{level 1}=[sibling distance=8mm]
\node (1){$\mathtt{atom}$}
child {node (2){$\mathtt{atom}$}}
child {node (3){$\mathtt{int}^2$}}
child {node (4){$\mathtt{collection}$}
child {node (5){$\mathtt{int}$}}};
\end{scope}
\end{tikzpicture}
}
\end{document}
답변1
every node/.append style={anchor=base}
모든 노드가 기준점에 정렬되도록 간단히 추가할 수 있습니다.
암호
\documentclass{book}
\usepackage{tikz}
\begin{document}
{\tiny
\begin{tikzpicture}
\begin{scope}[level distance=6mm,every node/.append style={anchor=base}]
\tikzstyle{level 1}=[sibling distance=8mm]
\node (1){$\mathtt{atom}$}
child {node (2){$\mathtt{atom}$}}
child {node (3){$\mathtt{int}^2$}}
child {node (4){$\mathtt{collection}$}
child {node (5){$\mathtt{int}$}}};
\end{scope}
\end{tikzpicture}
}
\end{document}
산출
답변2
anchor=base
나무의 열쇠를 사용하세요 .
예
\documentclass{book}
\usepackage{tikz}
\begin{document}
{\tiny
\begin{tikzpicture}
\begin{scope}[level distance=6mm, anchor=base]
\tikzstyle{level 1}=[sibling distance=8mm]
\node (1){$\mathtt{atom}$}
child {node (2){$\mathtt{atom}$}}
child {node (3){$\mathtt{int}^2$}}
child {node (4){$\mathtt{collection}$}
child {node (5){$\mathtt{int}$}}};
\end{scope}
\end{tikzpicture}
}
\end{document}