1

The following code shows an ugly way to fix the bad vertical positioning of the labels in a top-down phylogenetic graph. How to avoid the special fixing style done by hand? How to find the good style to be fixed?

enter image description here

% Source: https://tex.stackexchange.com/a/133237/6880

\documentclass[12 pt]{article}

\usepackage{tikz} \usetikzlibrary{graphs, graphdrawing} \usegdlibrary{phylogenetics}

\pgfgdset{ phylogenetic inner node/.style = { /tikz/.cd, draw, circle, inner sep=0pt, minimum size=5pt } }

\begin{document}

\begin{tikzpicture} \graph[ phylogenetic tree layout, upgma, distance matrix = { % a b c d e f g 0 4 9 9 9 9 9 % a 4 0 9 9 9 9 9 % b 9 9 0 2 7 7 7 % c 9 9 2 0 7 7 7 % d 9 9 7 7 0 3 5 % e 9 9 7 7 3 0 5 % f 9 9 7 7 5 5 0 % g }] { a, b, c, d, e, f, g }; \end{tikzpicture}

\begin{tikzpicture}[ test/.append style={font=\vphantom{Vg}} ] \graph[ phylogenetic tree layout, upgma, distance matrix = { % a b c d e f g 0 4 9 9 9 9 9 % a 4 0 9 9 9 9 9 % b 9 9 0 2 7 7 7 % c 9 9 2 0 7 7 7 % d 9 9 7 7 0 3 5 % e 9 9 7 7 3 0 5 % f 9 9 7 7 5 5 0 % g }] { a[test], b[test], c[test], d[test], e[test], f[test], g[test] }; \end{tikzpicture}

\end{document}

projetmbc
  • 13,315

1 Answers1

2

You can set the option text height for every node so something sensible (additionally, depending on the use case, setting text depth is also a good idea):

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{phylogenetics}

\pgfgdset{ phylogenetic inner node/.style={ /tikz/.cd, draw, circle, inner sep=0pt, minimum size=5pt } }

\tikzset{ every node/.style={text height=1.25ex} }

\begin{document} \begin{tikzpicture} \graph[phylogenetic tree layout, upgma, distance matrix = { 0 4 9 9 9 9 9 4 0 9 9 9 9 9 9 9 0 2 7 7 7 9 9 2 0 7 7 7 9 9 7 7 0 3 5 9 9 7 7 3 0 5 9 9 7 7 5 5 0 }] { a, b, c, d, e, f, g }; \end{tikzpicture} \end{document}

enter image description here


Why does this help here? You can best see the effect by temporarily adding a border to the nodes:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{phylogenetics}

\pgfgdset{ phylogenetic inner node/.style={ /tikz/.cd, draw, circle, inner sep=0pt, minimum size=5pt } }

\tikzset{ every node/.style={text height=1.5ex, text depth=0.33ex, draw} }

\begin{document} \begin{tikzpicture} \graph[phylogenetic tree layout, upgma, distance matrix = { 0 4 9 9 9 9 9 4 0 9 9 9 9 9 9 9 0 2 7 7 7 9 9 2 0 7 7 7 9 9 7 7 0 3 5 9 9 7 7 3 0 5 9 9 7 7 5 5 0 }] { a, b, c, d, e, f, g }; \end{tikzpicture} \end{document}

enter image description here

Without text depth set:

enter image description here

Without text height (and without text depth) set:

enter image description here

  • 1
    Using it via \begin{tikzpicture}[every node/.style={text height=1.25ex}] ... \end{tikzpicture} does the job. Thanks. – projetmbc Feb 21 '23 at 19:48
  • 1
    @projetmbc Sure, this is also a way to go. I added some pictures to show what is happening and why setting text height and text depth helps in this case. – Jasper Habicht Feb 21 '23 at 19:51