15

Today, I had to deal with large number blocks with >10 digits. With my current setup, the whole number is shown without any grouping or decimal point, making it hard to read them, especially when they contain large amounts of zeros.

My preamble:

\documentclass[paper=a4, fontsize=12pt,]{scrartcl} 
% Für Spracheingaben und korrekte Trennung
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage[ngerman]{babel}

% Matherelevante Pakete
\usepackage[decimalsymbol=comma]{siunitx}
\usepackage{icomma}
\usepackage{amsmath}

% Sonstige Parameter
\setlength{\parindent}{0pt}
\numberwithin{equation}{subsection}

As you can see, I’m using commas as the regular decimal symbol, so a comma as a decimal point wouldn’t make too much sense.

Anyway, how do I get digits to be grouped automatically? So far, I’ve been using the following, manual way to achieve spacing between larger numbers, but that isn’t too comfortable:

\sqrt[2]{1,6 \cdot 10^{13}} = \sqrt[2]{16\,000\,000\,000\,000} &= 4\,000\,000\

intended ouput

So my question is: How do I get automatic digit grouping with the decimal point being either an apostrophe or a non-braking space?

7
  • 10
    \usepackage{siunitx} and \num{12345,67890} -> 12 345.678 90 \\
    – La Raison
    Nov 1, 2012 at 14:31
  • 2
    The apostrophe or the upper dot for separating groups of digits are frowned upon in typographic circles. A thin space is the best separator and, as @LaRaison says, it's provided by siunitx with the macro \num, possibly passing some options.
    – egreg
    Nov 1, 2012 at 14:34
  • @LaRaison: That still is rather manual. Also, I think it is awkward to have \num{} within equation- or align-brackets Nov 1, 2012 at 14:34
  • 3
    @PattaFeuFeu I don't think it's difficult to write: $\sqrt{\num{1.6e13}} = \sqrt{\num{16 000 000 000 000}} = \num{4 000 000}$. You can separate groups also in the input and \num will take care of reformatting them independently of the input format. If you have many decimal numbers it's even handier than relying on icomma: you can use either a comma or a dot in the input and the number will be formatted as requested with the options passed to siunitx.
    – egreg
    Nov 1, 2012 at 14:40
  • 1
    @PattaFeuFeu The decimalsymbol option is proper of version 1 of siunitx and forces it to use version 1 features. If you're not stuck with that version because of an outdated TeX distribution, it's better to use output-decimal-marker={,} for setting the comma.
    – egreg
    Nov 1, 2012 at 14:44

1 Answer 1

15

The siunitx package you're already loading provides the \num command for formatting numbers.

This command is very handy, because it allows to get output independently on how the input is formatted.

\documentclass[paper=a4, fontsize=12pt,]{scrartcl}
% Für Spracheingaben und korrekte Trennung
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

% Matherelevante Pakete
\usepackage[output-decimal-marker={,},exponent-product=\cdot]{siunitx}
\usepackage{icomma}
\usepackage{amsmath}

% Sonstige Parameter
\numberwithin{equation}{subsection}

\begin{document}

$\sqrt{\num{1.6e13}} = \sqrt{\num{16 000 000 000 000}} = \num{4 000 000}$

$\sqrt{\num{1,6e13}} = \sqrt{\num{16000000000000}} = \num{4000000}$

\end{document}

The two inputs will give the same output, namely

enter image description here

Note that decimalsymbol=comma is a "version 1" option, so it forces siunitx to use only the less powerful features present in version 1. The options I passed in the example are the "modern" ones.

In case you're stuck with the old version because of an outdated TeX distribution, update it or use

\usepackage[decimalsymbol=comma,expproduct=\cdot]{siunitx}

In any case, never use anything other than thin spaces for separating groups of digits.

6
  • Thank you very much. From now on, I’m trying to use \num{}in math-mode. Nov 1, 2012 at 14:57
  • @PattaFeuFeu Decimal numbers and "big" numbers, of course. There's no point in using \num to write \sqrt{42}; but for the said kinds of numbers it's very handy to be "input independent": for instance, you can change from "decimal comma" to "decimal period" just changing one option to siunitx.
    – egreg
    Nov 1, 2012 at 15:08
  • However, when using sqrt{\num{1.6e13}} prior to \sqrt{1.6\cdot10^{13}}, the height changes, where e13 makes the root box higher: picture – which one is, typographically speaking, “looking better”? I prefer the smaller one, to be honest. Nov 1, 2012 at 15:20
  • 1
    TeXnically speaking, the difference is due to the fact that \sqrt forces "cramped" style in its argument, which results in lowering superscripts if they're not accompanied by subscripts, while \num resurrects the "uncramped" style. I prefer the "uncramped" style, to be honest.
    – egreg
    Nov 1, 2012 at 15:29
  • 1
    @PattaFeuFeu Yes, that's the same; options can always be specified with \sisetup also in the middle of the document. This can be handy in a multilingual document, for instance. An option can also be set locally as optional argument to \num, \si or \SI.
    – egreg
    Nov 1, 2012 at 16:02

You must log in to answer this question.

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