I've taken the example from the pgfplots
manual on Preset SI prefixes
and modified it slightly, changing a prefix from milli
to micro
.
The result is that the units of the yaxis are stated as micro-Newton, a \mu
and a capital N. The \mu
is slanted here, which is what disturbs and surprises me. The siunitx
package (which I use everywhere else) would set the unit with an upright \mu
. That's what I'd like to happen here as well.
Here's a rendering of this sample document:
\documentclass[preview]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\pgfplotsset{width=7cm,compat=1.11}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\begin{axis}[change x base,
x SI prefix=kilo,x unit=m,
y SI prefix=micro,y unit=N,
xlabel=Distance,ylabel=Force (\si{\micro\newton})]
\addplot coordinates {
(1000,1)
(2000,1.1)
(3000,1.2)
(4000,1.3)
};
\end{axis}
\end{tikzpicture}
\end{document}
I thought I had found a solution for this when I came across the line
\pgfplotsset{unit code/.code 2 args={\si{#1#2}}}
in the pgfplots
manual, but this does not help because the micro
is passed to siunitx
as \mu
rather than \micro
.
Best Answer
I believe this is a bug in
tikzlibrarypgfplots.units.code.tex
. Take a look at lines 109-180, where the prefixes are defined. You'll find (formicro
only):This is what causes
\mu
to be passed even when usingas you mentioned. I'm not sure the best way to solve this in the general case (where the user is not guaranteed to be using
siunitx
), but here is a workaround for your case:More detailed discussion
The rest of the prefix lines also leave something to be desired when
siunitx
is being used. Here's a typical example:This does not follow the
siunitx
convention of using the literal prefix as acsname
. If we were to do that, the typical line would look like:but, of course, this would only work with
just as my workaround above. The ideal solution would involve significant modifications to the code, but perhaps an
siunitx
option could be considered (a lacircuitikz
), which resets all prefixes to the literal prefix as acsname
, and automatically sets upunit code
for usage withsiunitx
.To fix this when
siunitx
is not being used requires yet more modifications because of the default setup ofunit code
, which is entirely in math mode. Even if upright greeks were available, using them as part of theaxis base prefix
key is not allowed because we're not in text mode at that point.