![Code](https://rvso.com/image/281570/Code.png)
Ich habe einen Baum (siehe Beispiel), bei dem der Text auf Ebene 1 nicht ausgerichtet ist, da einer der Texte einen mathematischen Ausdruck mit einem Exponenten verwendet (z. B. $\mathtt{int}^2$
). Irgendeine Idee, wie man alle Texte, die sich auf derselben Ebene des Baums befinden, ausrichten kann?
\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}
Antwort1
Sie können einfach hinzufügen every node/.append style={anchor=base}
, so dass alle Knoten an ihrem Basispunkt ausgerichtet sind
Code
\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}
Ausgabe
Antwort2
Benutze den anchor=base
Schlüssel für den Baum.
Beispiel
\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}