テキストの 1 つに指数付きの数式 (つまり、 ) が使用されているため、レベル 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}