Closed IjhUDWzf closed 8 months ago
Pgf acts as expected. Surprisingly, minus math character -
in the default math symbol font has a non-zero depth, hence aligning at bottom makes $-3$
higher than $3$
.
Maybe using bottom
option of \pgftext
to align plot labels is not a good choice. Similarly, top
won't ensure result of aligning at baseline if height of \pgftext
s differ (for instance when old-style numbers are used). The base
option is what's needed here, but then one has to use estimated shiftings.
\documentclass{article}
\showboxbreadth=\maxdimen
\showboxdepth=\maxdimen
\begin{document}
\setbox0=\hbox{$3$}
\showbox0
\setbox0=\hbox{$-$}
\showbox0
\end{document}
> \box0=
\hbox(6.44444+0.0)x5.00002
.\mathon
.\OT1/cmr/m/n/10 3
.\mathoff
> \box0=
\hbox(5.83333+0.83333)x7.7778
.\mathon
.\OMS/cmsy/m/n/10 ^^@
.\mathoff
Thank you @muzimuzhi for explaining. When I replaced bottom
with base
in the code generated by matplotlib the alignment seems to be perfect even without any shifts (even when I only replace bottom
with base
for negative numbers). The issue seems to be on the matplotlib side then.
Brief outline of the bug
When text is aligned to bottom and a
minus
is present the vertical alignment does not match the same text without theminus
.Context: I use pgf backend of matplotlib and noticed that ticks labels are positioned incorrectly. While investigating the issue I found out that labels below the graph (aligned to top) are fine while labels above the graph (aligned to bottom) are incorrect. Moreover, the coordinates produced by matplotlib do seem to be ok.
Version of pgf: v3.1.8b
Minimal working example (MWE)