我在 pgf 上使用科学计数法来显示数字。我现在的代码如下:
\documentclass{article}
\usepackage{pgf}
\begin{document}
\pgfkeys{
/pgf/number format/.cd,
sci,
sci generic={mantissa sep=\times, exponent={10^{#1}}},
sci zerofill,
precision=1
}
\pgfmathprintnumber{350}\hspace{1em}
\pgfmathprintnumber{12}\hspace{1em}
\pgfmathprintnumber{4.568}\hspace{1em}
\pgfmathprintnumber{0.1}\hspace{1em}
\pgfmathprintnumber{0.012}\hspace{1em}
\end{document}
结果如下:
3.5×10^2 1.2×10^1 4.6×10^0 1.0×10^−1 1.2×10^-2
但是,我不想只显示 10^(-1)、10^0 和 10^1。我想显示如下:
3.5×10^2 12 4.6 0.10 1.2×10^-2
我应该如何改进我的代码?
答案1
使用std
密钥:
\documentclass{article}
\usepackage{pgf}
\begin{document}
\pgfkeys{
/pgf/number format/.cd,
sci,
std={-1:1},
sci generic={%
mantissa sep=
{
\times
},
exponent={
10^{#1}%
},
},
sci zerofill,
precision=1
}
\pgfmathprintnumber{350}\hspace{1em}
\pgfmathprintnumber{12}\hspace{1em}
\pgfmathprintnumber{4.568}\hspace{1em}
\pgfmathprintnumber{0.1}\hspace{1em}
\pgfmathprintnumber{0.012}\hspace{1em}
\end{document}
答案2
\documentclass{article}
\usepackage{pgf}
\begin{document}
\pgfkeys{/pgf/number format/.cd,sci,precision=2}
\pgfmathprintnumber{350}\hspace{1em}
\pgfkeys{/pgf/number format/.cd,std,precision=1}
\pgfmathprintnumber{12}\hspace{1em}
\pgfmathprintnumber{4.568}\hspace{1em}
\pgfkeys{/pgf/number format/.cd,std,precision=2}
\pgfmathprintnumber{0.1}\hspace{1em}
\pgfkeys{/pgf/number format/.cd,std,precision=1}
\pgfmathprintnumber{0.012}\hspace{1em}
\end{document}