Eu tenho uma árvore (ver exemplo) para a qual o texto no nível 1 não está alinhado, pois um dos textos usa alguma expressão matemática com um expoente (ou seja, $\mathtt{int}^2$
). Alguma ideia de como alinhar todos os textos que estão localizados no mesmo nível da árvore?
\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}
Responder1
Você pode simplesmente adicionar every node/.append style={anchor=base}
para que todos os nós fiquem alinhados em seu ponto base
Código
\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}
Saída
Responder2
Use a anchor=base
chave da árvore.
Exemplo
\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}