2

I want to export the figure in scientific notation form, for example, the number 1.25e-8 should be $1.25\times 10^{-8} $. However I found that if I use the pre-defined style as the option for pgfmathprintnumber, the exponent will not appear. For example,

\documentclass{article}
\usepackage{tikz}
\begin{document}
    \pgfkeys{
    /pgf/number format/.cd,
    sci,
    sci generic={mantissa sep=\times,exponent={10^{#1}}}}
    \pgfmathprintnumber{1.25e-8}


    \tikzset{
       /pgf/number format/scinum/.style={
         sci,
         sci generic={mantissa sep=\times,exponent={10^{#1}}},
         },
      }
    \pgfmathprintnumber[scinum]{1.25e-8}
\end{document}

The first result is in the correct form whereas the second one lost the exponent.

How can I solve this problem?

Ice0cean
  • 1,646

1 Answers1

2

This is not a genuine pgf issue, but a LaTeX thingy: if you define something inside a definition, you need to add a #, see e.g. this post. That is, you need to replace #1 by ##1 in the \tikzset command.

\documentclass{article}
\usepackage{tikz}
\begin{document}
    \pgfkeys{
    /pgf/number format/.cd,
    sci,
    sci generic={mantissa sep=\times,exponent={10^{#1}}}}
    \pgfmathprintnumber{1.25e-8}


    \tikzset{
       /pgf/number format/scinum/.style={
         sci,
         sci generic={mantissa sep=\times,exponent={10^{##1}}},
         },
      }
    \pgfmathprintnumber[scinum]{1.25e-8}
\end{document}

enter image description here