# PGFplots: loglogaxis: Shrink the exponent's minus sign

I do have a lot of loglogaxis plots in my document. Often the y-values pass through 1, i.e. from 0.5 to 2. Hence, the y-ticklabels are of the form .

The minus sign adds a lot of extra space to the spacing of the y-label. I would like to stick with 10-base notation of the y tick labels. In this case,I do not want to use

log ticks with fixed point


I already found, how to shrink the minus sign. How can I change specifically all the minus sign in the exponents of the tick labels in pgfplots?

MWE:

\documentclass{minimal}
\usepackage{pgfplots}

\begin{document}

$$\sqrt{\scalebox{0.5}[1.0]{\( -$$}\frac{1}{9}} \)

% cf.
$$\sqrt{-\frac{1}{9}}$$

\begin{tikzpicture}
\begin{loglogaxis}[
xlabel={xlabel is nicely separated},
ylabel={ylabel is displaced to far}
]
table{
x     y
0.1   0.1
1.0   1.0
10.0  10.0
};
\end{loglogaxis}
\end{tikzpicture}
\end{document}


Any help is highly appreciated. Thank you.

Sorry for such a late answer but I recently had to do the same and came across this post so I thought I'd share what I did, in case anybody else needs it.

I assume there is a much more automatic way but since I am new to pgfplots it follows the completely manual way of defininy the tick positions and ticklabels explicitly. This is probly not something you want to do if you have many of such plots.

Here the result:

The ytick and yticklabels are defined explicitly with the \unaryminus command defined earlier for convenience. Although optional, I find it convenient to let latex calculate the width of the longest label with \settowidth and then set that as the text width in the yticklabel style as well as set the alignment to right.

\documentclass{article}
% replaced minimal class with article, which is more appropriate for MWEs
\usepackage{pgfplots}
\newcommand\unaryminus{\smash{\scalebox{0.5}[1.0]{$$-$$}}}
% \smash is used here to reduce the depth of the minus sign in the superscript, so the xlabels have the same height
\begin{document}

\newlength{\mylabelwidth}
\settowidth{\mylabelwidth}{$10^{\unaryminus 1}$}

\begin{tikzpicture}
\begin{loglogaxis}[
xlabel={xlabel is nicely separated},
ylabel={ylabel is also nicely aligned},
ytick={0.1, 1,10, 100},
yticklabels={$10^{\unaryminus 1}$,$10^{0}$,$10^{1}$,$10^{2}$},
yticklabel style={
text width=\mylabelwidth,
align=right, % alternatively use "left"
},
xtick={0.1, 1,10, 100},
xticklabels={$10^{\unaryminus 1}$,$10^{0}$,$10^{1}$,$10^{2}$},
]
table{
x     y
0.1   0.1
1.0   1.0
10.0  10.0
100.0  100.0
};
\end{loglogaxis}
\end{tikzpicture}
\end{document}


P.S.: The compat=newest was added to stop pgfplots throwing a warning. It works without it. Also if somebody knows how to generate the labels and ticks automatically I'd be very much interested in that!

• Thanks @Schweinebacke, I did not know that. Fixed it. Am I supposed to declare the edit explicitly in the answer itself or is it OK if I just edit it? I could not find a definitive style guide for that. – DrBones Nov 13 '17 at 12:12
• It's OK to just edit it. But it would also be good to explain, why you change something. See, e.g., Tørbjorns answer. – Schweinebacke Nov 13 '17 at 14:56
• No need for apologies. Thank you for your answer. I solved this issues the same way, but didn't found the time to post here. I like your \unaryminus macro. I personally prefer the right aligned yticklabels. Did you spotted the hanging first xticklabel? I solved this with the \smash command: \newcommand\unaryminus{\smash{\scalebox{0.5}[1.0]{$$-$$}}}. Would you add this to your answer? And still, having this automated, would be great! – somehow.different Nov 14 '17 at 8:39
• For the vertical height and depth of superscripts see here. This led me to \smash. – somehow.different Nov 14 '17 at 8:49
• Thank you both for your helpful comments. And no, I did not spot that but now it sticks out like a sore thumb. I would have never suspected a minus sign to have depth :). I added it to my answer and my thesis! – DrBones Nov 16 '17 at 9:53

You can move the ylabel closer to the axis, wouldn't that be a better method? With compat=1.3 or higher, you can add ylabel shift=-5pt to move it 5pt closer to the axis.

Unrelated note: Why should the minimal class be avoided?

\documentclass{article}
\usepackage{pgfplots}
% compat setting of 1.3 or higher required for ylabel shift to work
\pgfplotsset{compat=1.3}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[
xlabel={xlabel is nicely separated},
ylabel={ylabel is displaced to far},
ylabel shift=-5pt
]