70

In most language, long numbers are split into groups of three digits, to increase readability.

In Dutch (my native language), 1000000 is usually written as 1 000 000. In English, this would be 1,000,000.

Now, I would like to know how to use this kind of formatting in LaTeX. I searched google, but I only found some articles that explain how to split very long numbers over multiple lines, which is not what I need.

Is there a package that does this automatically? Or a certain tag I can use for this?

4
  • sorry I didn't realize it was latex, anyway searching "number formatting" will help you find something instead of split. for example this post: latex-community.org/forum/viewtopic.php?f=44&t=9548 hope it helps
    – aleation
    Commented Apr 23, 2013 at 9:45
  • 12
    siunitx provides this functionality.
    – Werner
    Commented Apr 23, 2013 at 14:20
  • 5
    Or numprint
    – Joseph Wright
    Commented Apr 23, 2013 at 15:21
  • +1 for narrow space separation. I was taught in primary school in the Netherlands to use a dot, and that the Americans use a comma but that dot is european so we should use this. Later, I learned of other options like space and apostrophe which are unmistakable for a decimal separator and that just sounds like the obvious solution.
    – Luc
    Commented Dec 1, 2022 at 20:23

5 Answers 5

66

You can use \, for a thin space if you are entering by hand: $1\,000\,000$

You can also use a package such as siunitx, which inserts appropriate separators and spacing automatically: \num{100000}

Which one you should use depends on what you want to do (and where the numbers are generated); whether it's a few numbers in a hand-authored text or if you are typesetting thousands of numbers in table data where hand editing to add grouping separator is not really an option.

5
  • Is there any method to automatically apply siunitx to all the numbers of my document without needing to write \num in front of each one? I would like to have all my numbers shown with groups of 3 digits and a small space in between.
    – skan
    Commented Oct 27, 2020 at 19:52
  • @skan not really (but you could ask a new question see if anyone has any suggestions) Commented Oct 27, 2020 at 20:02
  • 2
    ... and how do you do it with siunitx?
    – Mayou36
    Commented Oct 13, 2023 at 14:58
  • @Mayou36 I've edited the answer to answer your question: use \num{1000000}.
    – FWDekker
    Commented Mar 13 at 17:12
  • 1
    @FWDekker thanks Commented Mar 13 at 17:22
30

There is a good package for all of these formatting issues with numbers, either in text or in tabular: \usepackage{numprint}. Please study the manual, it provides a lot of detailed information. You get the manual usually with something like texdoc numprinton the command line.

A small MWE for numprint to answer your question:

\documentclass[english]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{numprint}
\npthousandsep{\,}

\begin{document}

This would be a line with a price tag: \numprint{1000000} EUR.

And as a tabular: 
\begin{tabular}{N{7}{0}}
  1000000 {~EUR}\\
\end{tabular}
\end{document}

We get this:

numprint example

As you can see, just tell numprint how the thousand separator should look like. You can do much more, rounding numbers e.g.

4
  • 4
    Note that numprint have an option to specify the unit this way \numprint[EUR]{1000000} or \numprint[nm^2]{5}
    – Opsse
    Commented Jul 13, 2020 at 17:30
  • @Opsse I'm astonished, never noticed that option. Thank you!
    – Keks Dose
    Commented Jul 14, 2020 at 9:00
  • Am I missing something here? You set \npthousandsep{\,}, but the rendered separator is a space.
    – crockeea
    Commented Oct 4, 2023 at 17:59
  • @crockeea \, delivers a thin space.
    – Keks Dose
    Commented Oct 5, 2023 at 14:55
5

This is very interesting exercise for TeX macro programmers. My result looks like this:

\def\num #1{\numA#1\empty\empty\empty#1\end}
\def\numA #1#2#3{%
   \ifx #1\empty \afterelax{\numB}\fi
   \ifx #2\empty \afterelax{\numB{}}\fi
   \ifx #3\empty \afterelax{\ea\numB\ignoreit}\fi
   \ea \numA \ignoreit \relax
}
\def\numB #1#2#3#4{#1#2#3\ifx#4\end\else \numseparator \ea\numB\ea#4\fi}

\def\afterelax#1#2\relax{\fi#1}
\def\ignoreit#1{}
\let\ea=\expandafter

\def\numseparator{,}

Test: number \num{1234567}

The \num macro is expandable.

3

Well, the package SIUNITX has solved this problem easily. Try\usepackage[round-mode=places,round-precision=2,group-separator={,},output-decimal-marker={.}]{siunitx} in your preamble, and use \num{10000}. For more usages see its CTAN manual.

1
  • 1
    Add round-pad = false to avoid zeros at the decimal place for integers.
    – KarelZe
    Commented Mar 2, 2023 at 18:32
1

Use the package "Ziffer" which helps if you want to write 100000 as "100.000,00" it will show "10 000,00" (no space after the comma and a space instead of the dot)

2
  • 12
    Please improve your answer with small. complete document, which will show syntax of using mentioned package.
    – Zarko
    Commented Jul 24, 2016 at 18:23
  • 2
    Your comment would technically apply to the accepted answer as well.
    – Mitja
    Commented Sep 18, 2017 at 18:43

You must log in to answer this question.

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