Siunitx in table: unexpected spacing

siunitxtables

Consider the following example.

\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}

\makeatletter
\newcommand*\numtablerange[1][]{%
  \kernel@ifnextchar[{\numtable@range{#1}}{\numtable@range{#1}[#1]}}
  \def\numtable@range#1[#2]#3#4{%
    \numtablerange@boxme{\expandafter\tablenum\expandafter[\numtablerange@lopt,#1]{#3}}--%
    \numtablerange@boxme{\expandafter\tablenum\expandafter[\numtablerange@ropt,#2]{#4}}%
  }
\newcolumntype{T}[3]{>{\def\numtablerange@lopt{#1}\def\numtablerange@ropt{#2}}#3}
\newcommand*\numtablerange@boxme[1]{{\sbox0{#1}\usebox0}}
\makeatletter

\begin{document}

\begin{table}
  \begin{tabular}{
    T{table-format = 2.2, output-decimal-marker = {:}}
     {table-format = 2.2, output-decimal-marker = {:}}
     {c}
  }
   \toprule
    {Tidsrum}                    \\
   \midrule
    \numtablerange{ 9.00}{10.00} \\
    \numtablerange{10.00}{11.00} \\
   \bottomrule
  \end{tabular}
\end{table}

\end{document}

output

Question

Years ago I compiled some code (of which the example above is a snip) which didn't result in the space after the colon, as far as I remember. I cannot figure out why it is there.

How do I remove the space after the colon?

Thought

I think it might be do to something introduced in siunitx v3 but I'm not sure at all.

Best Answer

I recommend explicitly marking up where you want tokens to be treated as \mathord: output-decimal-marker = \mathord{:}. This will work in both v2 and v3, and has the advantage that it retains the semantic information which using simply {...} does not. That is useful for example when switching to text mode, where {...} has no special meaning and where appropriate replacement of \mathord by a text mode equivalent can be used to retain important information.

The reason you see a change is rather technical, and will only show in tabular alignment. In v2, table cells were constructed by formatting each part of the number separately. This was rather slow and meant that there was a need to do this separately from 'normal' numbers, leading to some edge case bugs. For v3, I have picked up an idea from pgfplotstable: format using a marker between each part for alignment. For a normal number, the marker is empty and nothing is different. For an alignment, the marker is used to split out the various parts of the number, meaning alignment is faster and not using a different formatting path.

The issue arises as TeX removes braces if we match the entirety of a delimited argument in one go:

\def\foo#1X#2X#3\stop{\showtokens{#2}}
\foo stuffX{content}X\stop
\foo stuffX{content} X\stop

That means that a single extra set of braces around an entire numerical part will be dropped: usually not an issue but a problem if you are using {X} not \mathord{X} to make a symbol mathord. I could change the table setup to avoid this, but then I'd be back to a slower setup (there are lots of parts of a number I'd have to cover).

If you don't want to use \mathord, you can use an additional set of braces, which will deal with the issue. Or you could say add some space inside braces, which would be ignored in math mode but which would also prevent brace stripping.

Related Question