9

Here is an example replicating a problem I faced using the xticklabels from table feature:

\documentclass{article}

\usepackage{pgfplots}
\usepackage{tikz}

\usepackage{siunitx}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xtick={1e-4, .1, .3},
    xticklabels={\num{e-4}, .2, .3},
    ]
    \addplot[only marks] table[x=x, y=y] {
      x y
      -.3 .7
      .2 .1
      .5 .6
      0.4 -0.5
    };
  \end{axis}
\end{tikzpicture}
\end{document}

and a picture of the output:

sample output

The xticklabels are not properly aligned on their baseline. I suppose I could correct this by altering the xticklabels properties or maybe by using another way to format the numbers. What would be the bette way to ensure proper alignment?

8

You can fix the text height by setting xticklabel style={text height=2ex}:

\documentclass{article}

\usepackage{pgfplots}
\usepackage{tikz}

\usepackage{siunitx}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xtick={1e-4, .1, .3},
    xticklabels={\num{e-4}, 0.2, 0.3},
    xticklabel style={text height=2ex}
    ]
    \addplot[only marks] table[x=x, y=y] {
      x y
      -.3 .7
      .2 .1
      .5 .6
      0.4 -0.5
    };
  \end{axis}
\end{tikzpicture}
\end{document}
3

There is a better answer — just add style typeset ticklabels with strut.

2

The easiest and fastest way that comes to my mind is to add a phantom exponent:

enter image description here

\documentclass{article}

\usepackage{pgfplots}
\usepackage{tikz}

\usepackage{siunitx}
\newcommand{\pe}[1]{$#1^{\vphantom{1}}$}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xtick={1e-4, .1, .3},
    xticklabels={\num{e-4}, \pe{0.2}, \pe{0.3}},
    ]
    \addplot[only marks] table[x=x, y=y] {
      x y
      -.3 .7
      .2 .1
      .5 .6
      0.4 -0.5
    };
  \end{axis}
\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.