Menu

#45 Improper base alignment axis legend with old style figures

v1.0 (example)
closed-fixed
nobody
None
3
2014-12-03
2012-04-10
No

When using old-style figures for labelling an axis, the numbers are not properly aligned. This is most easily demonstrated with an example, see the attached screenshot.

Thanks for considering my report. And no, this is no spam such as the five last few posts :-(.

Discussion

  • Anonymous

    Anonymous - 2012-04-10

    Notice the alignment of 2006

     
  • Christian Feuersänger

    • priority: 5 --> 3
     
  • Christian Feuersänger

    Thanks for the bug report!

    It is funny, sometimes I receive email notifications and sometimes not. Why did I not receive this one!? Seems I should not rely on sourceforge email notifications. Sorry for the late response.

    Anyway: I noted the problem.

    In the meantime, there are some ways to overcome this weakness:

    \documentclass[a4paper]{article}

    \usepackage{pgfplots}

    \pgfplotsset{compat=1.5}

    \begin{document}

    % 1. If you provided your tick labels explicitlcy: add \strut to the text:

    \begin{tikzpicture}
    \begin{axis}[xtick={1,2},xticklabels={\strut g,\strut G}]
    \addplot {x};
    \end{axis}
    \end{tikzpicture}

    % 2. if you simply have numerical content (as in your screenshot), add the following xticklabel=\strut... instruction:
    \begin{tikzpicture}
    \begin{axis}[xtick={1,2},xticklabel=\strut\pgfmathprintnumber{\tick}]
    \addplot {x};
    \end{axis}
    \end{tikzpicture}

    % 3. this here does also work: it uses the baseline as common alignment point and compensates the shifts explicitly:
    \begin{tikzpicture}
    \begin{axis}[xtick={1,2},xticklabels={g,G},xticklabel style={anchor=base,yshift=-\baselineskip}]
    \addplot {x};
    \end{axis}
    \end{tikzpicture}
    \end{document}

    I will think about a builtin solution for the next release (or the release after it).

    Best regards

    Christian

     
  • Christian Feuersänger

    • status: open --> closed-fixed
    • Group: --> v1.0 (example)
     
  • Christian Feuersänger

    I have fixed it; will become part of pgfplots 1.11 (if one uses \pgfplotsset{compat=1.11}).

    I have added \strut to every tick label. This will increase the bounding box for the figures... I hope that's no bad idea.

     
  • Christian Feuersänger

    I have reverted the modification of the default configuration: if I enable \strut for any ticklabel, the bounding box will be too large. This affects any normal axis and the special ones like polar axes even more.

    For now, I have just added a further key "typeset ticklabels with strut" which allows to enable this in a simple way... not really the best solution. My plan was to detect mismatches in the text depth/height and provide a meaningful warning. But that has its own challenges as it might disable "align" and "text width" for such labels.