1

With the following MWE:

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{intersections} %% named intersections
\usetikzlibrary{fit}
\usetikzlibrary{calc}


\begin{document}

\begin{tikzpicture}
\begin{axis}[
  width= 400pt,
  ymin = 0,
  ymax = 5,
  xmin = 0,
  xmax = 7,
  xtick = {0,1,...,7},
  scaled x ticks=real:2324823,
  xtick scale label code/.code={}, % this to not show extra scale label
]

\addplot [] coordinates {(0,0)};

\end{axis}
\end{tikzpicture}

\end{document}

... I'm getting xtick label formatting like this:

test_pdf

I would prefer less spacing between the numbers and the central dot - this is the previous image edited in Gimp to show my preference:

test_pdf2

Is this possible to do somehow - maybe through some settings for /pgf/number format/sci?

4
  • 1
    Instead of reducing the space (which gives inconsistent result), you can rotate them: x tick label style={inner xsep=0pt,rotate=45,anchor=north east},. – user11232 Feb 18 '14 at 1:25
  • 3
    As @HarishKumar notes, reducing the space will give inconsistent results. But if you really need to do it, adding \pgfkeys{/pgf/number format/sci generic={mantissa sep={\!\cdot\!},exponent={10^{#1}}}} inside the tikzpicture environment will do the trick. Adjust the spacing/kerning commands around the \cdot to your liking. – Paul Gessler Feb 18 '14 at 1:36
  • Thanks @HarishKumar - in this case, I'd rather not rotate the labels (although I do that kind of stuff often). I found a "manual" way, posted it below - I don't think it looks that bad... Cheers! – sdaau Feb 18 '14 at 1:41
  • Thanks @PaulGessler - that is exactly what I need; I've just learned a manual way to do that, and I've posted it below. Tried your suggestion and it automatizes it! If you don't mind posting that as answer, I will accept it; thanks again, cheers! – sdaau Feb 18 '14 at 1:45
2

Based on my comment:

As @HarishKumar notes, reducing the space will give inconsistent results. Scientific notation in the text of your document will not look the same, and in general it's not a good idea to fiddle with TeX's spacing recommendations. The \cdot is spaced out because it is a binary operator.

But if you really need to do it, you may add
[/pgf/number format/sci generic={mantissa sep={\!\cdot\!},exponent={10^{#1}}}]
to the tikzpicture options, as shown in the complete code below.

Alternatively, you can use braces around \cdot to override TeX's default operator spacing:
[/pgf/number format/sci generic={mantissa sep={{{\cdot}}},exponent={10^{#1}}}]
The extra set of braces is required to prevent the keyval system from treating the braces as another nesting level.

You may, of course, further adjust the spacing/kerning commands around the \cdot to your liking.

The code

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}

% Choose either one of the following two lines
%\begin{tikzpicture}[/pgf/number format/sci generic={mantissa sep={\!\cdot\!},exponent={10^{#1}}}]
\begin{tikzpicture}[/pgf/number format/sci generic={mantissa sep={{{\cdot}}},exponent={10^{#1}}}]
\begin{axis}[
  width= 400pt,
  ymin = 0,
  ymax = 5,
  xmin = 0,
  xmax = 7,
  xtick = {0,1,...,7},
  scaled x ticks=real:2324823,
  xtick scale label code/.code={}, % this to not show extra scale label
]

\addplot [] coordinates {(0,0)};

\end{axis}
\end{tikzpicture}

\end{document}

The output

enter image description here

1

Well, thanks to these questions:

... at least I found a manual way to do it - by manually typing and overriding xticklabels at the end of the axis setup:

...
  xtick scale label code/.code={}, 
  xticklabels={$0$, $4.3{\cdot}\!10^{-7}$, $8.6{\cdot}\!10^{-7}$, $1.29{\cdot}\!10^{-6}$, $1.72{\cdot}\!10^{-6}$, $2.15{\cdot}\!10^{-6}$, $2.58{\cdot}\!10^{-6}$, $3.01{\cdot}\!10^{-6}$ },
]
...

... which results with:

test_pdf

... which doesn't look bad at all - but who wants to type this kind of stuff manually :)

So if there's some automatic way to wrap the \cdot and add a negative math skip \! after it, that would be great to know...

4
  • 1
    You could pass \medmuskip=0em to every tick label. Or (I think better) write the labels like 1.72, 2.15, 2.58, etc. and on the side, a general {}\cdot 10^{-6}. – Manuel Feb 18 '14 at 2:11
  • 2
    @sdaau: You can save yourself the typing work by using the approach Paul Gessler described in his comment: Calling \pgfkeys{/pgf/number format/sci generic={mantissa sep={\!\cdot\!},exponent={10^{#1}}}} somewhere before the \begin{axis}. – Jake Feb 18 '14 at 6:53
  • Thanks @Jake - I was hoping @PaulGessler would have posted his comment as an answer, so I can accept it :) ; thanks @Manuel for the tip too ... Cheers! – sdaau Feb 18 '14 at 9:54
  • Sorry for the delay; my answer is there now! I wanted to do a bit of research to make a more comprehensive answer. :-) – Paul Gessler Feb 19 '14 at 14:44

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.