6

I use the siunitx package for typesetting numbers, units and ranges. When typesetting large ranges of numbers, for example "150 kHz to 8 MHz", I prefer the notation with different prefixes, i.e. "kilo" for the first number and "mega" for the second. However, I have not been able to typeset such a range using the siunitx macro \SIrange.

So far I have found two possibilities: Simply using "kHz" for both numbers. This leads to the (in my opinion) not very nice format "150 kHz to 8000 kHz", which I want to avoid. The only alternative I found was to manually create the two numbers using \SI, as illustrated in the following example.

\documentclass{article}
\usepackage{siunitx}
\begin{document}
    \SIrange{150}{8000}{\kilo\hertz}

    \SI{150}{\kilo\hertz} to \SI{8}{\mega\hertz}    
\end{document}

Is there any way to get an output similar to the second version (separate \SI's), but using \SIrange ? This would be nice, as it allows to globally change e.g. the range phrase ("to") and has a consistent spacing.

4
  • 1
    Would this be ok? \SIrange[scientific-notation = engineering,exponent-to-prefix = true, round-mode=figures]{150}{8000}{\kilo\hertz}. You can define that globally as well.
    – LaRiFaRi
    Aug 18, 2015 at 10:51
  • The exponent-to-prefix option is somehow what I'm looking for. Though I am not 100% happy with the "8.0 MHz". Especially if one needs a precision of 3 (e.g. for "125 kHz"), it would be "8.00 MHz" which isn't really what I want.
    – hbaderts
    Aug 18, 2015 at 10:59
  • 1
    @hbaderts You can also give the option zero-decimal-to-integer to make sure it is displayed as 8 MHz rather than 8.0 MHz or 8.00 MHz.
    – sodd
    Aug 18, 2015 at 11:18
  • Indeed, your two comments combined (+ round-precision=3) gives the desired results! Not very short, but exactly what I need. Thanks for your help @LaRiFaRi and @nordev. Does anybody of you want to post this as an answer?
    – hbaderts
    Aug 18, 2015 at 11:25

1 Answer 1

3

This answer got outdated with later versions of siunitx. Version 2015/01/21 v2.6e was used here.


I think the shortest form for what you want would be:

% arara: pdflatex

\documentclass{article}
\usepackage{siunitx}
\sisetup{%
    ,exponent-to-prefix = true
    ,zero-decimal-to-integer
    }

\begin{document}
    \begin{tabular}{l}
            \SIrange[scientific-notation = engineering]{150}{8000}{\kilo\hertz}\\
            \SIrange[scientific-notation = engineering]{100}{50000}{\tesla}\\
            \num{1234.1245345}
    \end{tabular}
\end{document}

You have to set the scientific notation locally in order not to change the normal numbers. You will have to decide, which options can be taken globally and which don't.

enter image description here

4
  • Your code did not produce these texts Apr 17, 2023 at 21:38
  • @RubemPacelli I have just tested this very code on Overleaf and it looked just like my screenshot.
    – LaRiFaRi
    Apr 21, 2023 at 9:16
  • That is weird. I just copied and paste your code on Overleaf and it didn't produce the same result. Take a look: ibb.co/rZYhvFg Apr 24, 2023 at 8:14
  • 1
    ah ok, you are right. My overleaf was set to tex-live 2014... :-) So there was a change between siuntix 2015/01/21 v2.6e which I was using here and 2022-06-07 v3.1.3 which I have now. Sorry for the confusion.
    – LaRiFaRi
    Apr 24, 2023 at 12:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .