I want to change the multiplication sign of the scientific notation of the siunitx
package to be \cdot
instead of \times
, but without changing the locale
option. How can I do that?
[Tex/LaTex] siunitx: change multiplication symbol in scientific notation
formattingscientific notationsiunitx
Related Solutions
While siunitx
is good at aligning a series of numbers in a similar format, it is less good for this type of mixed input. My initial thought would be
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{S[table-format = -1.6e1, table-align-exponent = false]}
3,158722 \\
-0,00061 \\
6,28E-05 \\
0,000303 \\
1,67E-04 \\
0,000175 \\
-0,00017 \\
0,000025 \\
-0,00012 \\
-7,7E-05 \\
-0,00042 \\
-0,0005 \\
0,128871 \\
-0,00689 \\
0,004255 \\
-0,00245 \\
0,010475 \\
0,007083 \\
0,000852 \\
0,004583 \\
-0,00042 \\
0,002032 \\
-0,00111 \\
0,000556 \\
12,53887 \\
0,0024 \\
-0,00387 \\
0,002836 \\
-0,00052 \\
-0,00022 \\
5,41E-05 \\
-0,00063 \\
3,17E-04 \\
0,000187 \\
-0,08153 \\
-0,07881 \\
0,316826 \\
0,001066 \\
0,009783 \\
-0,02701 \\
0,006054 \\
0,004167 \\
\end{tabular}
\end{document}
but this will have too much space on the right margin. Perhaps a new option is needed in siunitx
to handle this case.
One alternative approach is to use a strategy similar to the dcolumn
package, making both ,
and E
active in math mode:
\documentclass{article}
\usepackage{array}
\newbox\tabboxa
\newbox\tabboxb
\newcommand*\tabalignstart{%
\setbox\tabboxa=\hbox{$-1$}%
\setbox\tabboxa=\hbox to \wd\tabboxa
\bgroup
$
\lccode`\~=`\,\relax
\mathcode`\,="8000%
\lowercase{\def~}%
{%
$%
\egroup
\setbox\tabboxb=\hbox
\bgroup
$
\lccode`\~=`\E\relax
\mathcode`\E="8000%
\lowercase{\def~}####1####2####3%
{\times 10^{####1####3}}%
.
}%
\hfill
}
\newcommand*\tabalignstop{%
$
\hfil
\egroup
\box\tabboxa
\box\tabboxb
}
\begin{document}
\begin{tabular}{>{\tabalignstart}l<{\tabalignstop}}
3,158722 \\
-0,00061 \\
6,28E-05 \\
0,000303 \\
1,67E-04 \\
0,000175 \\
-0,00017 \\
0,000025 \\
-0,00012 \\
-7,7E-05 \\
-0,00042 \\
-0,0005 \\
0,128871 \\
-0,00689 \\
0,004255 \\
-0,00245 \\
0,010475 \\
0,007083 \\
0,000852 \\
0,004583 \\
-0,00042 \\
0,002032 \\
-0,00111 \\
0,000556 \\
12,53887 \\
0,0024 \\
-0,00387 \\
0,002836 \\
-0,00052 \\
-0,00022 \\
5,41E-05 \\
-0,00063 \\
3,17E-04 \\
0,000187 \\
-0,08153 \\
-0,07881 \\
0,316826 \\
0,001066 \\
0,009783 \\
-0,02701 \\
0,006054 \\
0,004167 \\
\end{tabular}
\end{document}
Of course, the problem then is that there are no digit separators.
Fist solution (doing it manually)
With the normal preferences, siunitx prints the numbers in the way, you type them in. 0.000001
is not printed in normal decimal mode, 1.234e5
is printed in the scientific mode. here a minimal working example:
\documentclass[12pt]{article}
\usepackage{siunitx}
\sisetup{
tight-spacing = true,
input-open-uncertainty = ,
input-close-uncertainty = ,
round-mode = places,
round-precision = 3,
table-space-text-pre = (,
table-space-text-post = )\Star,
table-align-text-pre = false
}
\protected\def\Star{$\text{*}$}
\begin{document}
\begin{tabular}{l*{4}{S}}
2006 & 4e-4 & -0.0282\Star & 3e-4 & -0.0015\\
& (0.0361) & (0.0229) & (0.1285) & (0.0539)\\
2011 &-2e-4 &-0.0315 & 0.0083 & 0.0037\\
\end{tabular}
\end{document}
And here the result:
Update: second solution (doing it automatically)
Here is a version which checks automatically the numbers and format them correctly. First it checks, if the number is in the range between 0.001 and 100, or -0.001 and -100. Then \pgfmathprintnumberto
is used to create a macro containing the number in a verbatim-like scientific form (e.g.1.234e5
), which is interpreted with siunitx.
Update2: Mirco had the right solution for the parenthesis spacing problem, and I edit my answer including his hint.
\documentclass[12pt]{article}
\usepackage{etoolbox}
\usepackage{tikz}
\usepgflibrary{fpu}
\usepackage{siunitx}
\sisetup{
tight-spacing = true,
input-open-uncertainty = ,
input-close-uncertainty = ,
round-mode = places,
round-precision = 3,
table-space-text-post = )\Star,
input-symbols = (
}
\protected\def\Star{$\text{*}$}
\def\mynum{}
\newcommand{\testnum}[1]{\begingroup%
\pgfmathparse{or(and(#1<100,#1>=0.001), and(#1>-100,#1<=-0.001))}%
\globaldefs=1\relax\ifnumequal{\pgfmathresult}{1}%
{\pgfkeys{/pgf/number format/.cd, fixed, precision=3, verbatim}}% printing 12300
{\pgfkeys{/pgf/number format/.cd, sci, sci e, precision=3, verbatim}}% printing 1.23e4
\pgfmathprintnumberto{#1}{\mynum}\endgroup}
\begin{document}
\begin{tabular}{l*{4}{S}}
2006 & {\testnum{0.0004}}\mynum & {\testnum{-0.0282}}\mynum\Star &
{\testnum{0.0003}}\mynum & {\testnum{-0.0015}}\mynum\\
& {\testnum{0.0361}}(\mynum) & {\testnum{0.0229}}(\mynum) &
{\testnum{0.1285}}(\mynum) & {\testnum{0.0539}}(\mynum)\\
2011 & {\testnum{-0.0002}}\mynum & {\testnum{-0.0315}}\mynum &
{\testnum{0.0083}}\mynum & {\testnum{0.0037}}\mynum\\
\end{tabular}
\end{document}
Here the result:
Best Answer
The
locale
option just changes the values ofexponent-product
andoutput-product
(andoutput-decimal-marker
). You just need to change those manually: