Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a big question about the siunitx package and I hope somebody out there can help me.

At first I want to use the automatic number conversion of the package. So I defined:

\sisetup{scientific-notation = engineering}

But now every number is converted into the engineering format. For example: 0.01 => 10x10^3 But I want that this number is not converted automatically.

Is there an option to adjust, which tells the package at which max. Exponent number this conversion to scientific-notation should take place?

I have really a lot numbers in a paper and it would be really hard to put the scientific-notation on or off for each number manually.

share|improve this question
    
Welcome to TeX.sx! You don't have to sign with your name since it automatically appears in the lower right corner of your post. –  Werner Feb 23 '12 at 15:02
add comment

2 Answers 2

I do not see anything in the documentation to control this behavior.

For the case where there are a few exceptions, you can manually switch it off for the ones you want with the \num[scientific-notation=false]{}.

Alternatively, if you can define exactly when you want the exponent to be added you can redefine the behavior of \num based on its value. Below I have defined \num to apply scientific-notation=false if

-\Threshold <= number <= \Threshold

where \Threshold is a value you define. With \Threshold=0.09 you get the results in the New column below for the value given in the Num column:

enter image description here

Notes:

  • In the question it is suggested to use a maximum exponent to determine if scientific notation is to be used. I am not sure that such a solution is viable in general. Perhaps a solution based on the number of digits might work. Once a better algorithm is determined, the macro \IfLessThanOrEqual can be adjusted to suit.

Code:

Below I have adapted this solution from how to test if a number is negative to define \IfLessThanOrEqual:

\documentclass{article}
\usepackage{siunitx}
\usepackage{tikz}

\sisetup{scientific-notation = engineering}
\newcommand*{\Threshold}{0.09}%

\newcommand\IfLessThanOrEqual[4]{%
    \begingroup%
        \pgfmathsetmacro{\var}{abs(#1)-#2}%
        \pgfmathparse{ifthenelse(\var<=0,1,0)}%
        \ifdim\pgfmathresult pt= 1 pt%
                #3%
            \else%
                #4%
        \fi%
    \endgroup%
}%

\let\OldNum\num%
\renewcommand*{\num}[2][]{%
    \IfLessThanOrEqual{#2}{\Threshold}{%
        \OldNum[scientific-notation=false,#1]{#2}%
    }{%
        \OldNum[#1]{#2}%
    }%
}%


\begin{document}
\newcommand{\Row}[1]{#1 & \OldNum{#1} & \num{#1}}%

\begin{tabular}{l l l}
Num & Old & New\\
\Row{0.01}\\
\Row{0.09}\\
\Row{0.091}\\
\end{tabular}
\end{document}
share|improve this answer
add comment

The related question Scientific Notation Only For Large Numbers just got a perfect answer from Bruno le Floch, I supposed it would help to display it here as well.

The answer uses the package expl3 and defines a new command to test whether the number to be printed surpasses the threshold: \fpcmpTF.

\documentclass{article}
\usepackage{expl3,siunitx}
\sisetup{scientific-notation=true}
\ExplSyntaxOn
    \cs_new_eq:NN \fpcmpTF \fp_compare:nTF
\ExplSyntaxOff

\newcommand*{\ThresholdLow}{0.01} % Change to your taste
\newcommand*{\ThresholdHigh}{100}

\let\OldNum\num%
\renewcommand*{\num}[2][]{%
    \fpcmpTF{abs(#2)<=\ThresholdLow}{%
        \OldNum[scientific-notation=true,#1]{#2}%
    }{%
        \fpcmpTF{abs(#2)>=\ThresholdHigh}{%
            \OldNum[scientific-notation=true,#1]{#2}%
        }{%
            \OldNum[scientific-notation=false,#1]{#2}%
        }%
    }%
}%
\begin{document}
\newcommand{\Row}[1]{#1 & \OldNum{#1} & \num{#1}}%
\begin{tabular}{l l l}
Num & Old & New\\
\Row{0.01}\\
\Row{0.1}\\
\Row{1}\\
\Row{10}\\
\Row{100}\\
\end{tabular}
\end{document}

enter image description here

If you like this, then be sure to pass the vote to Bruno's answer at How to subtract both very large numbers and numbers smaller than one?.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.