# Alignment at specific character with S column from siunitx

To avoid starting a new question yet again, I'll use this tread as the problem is the same as the first one.

\documentclass{article}

\usepackage{booktabs,dcolumn}
\usepackage{calc}
\usepackage[locale=DE]{siunitx}

\newcommand*\mc[1]{\multicolumn{2}{c}{#1}}
\newcommand*\Alignment[1]{% Alignment at --'.
\multicolumn{1}{r@{}}{\llap{\makebox[\widthof{--}][c]{#1}}}
}

\begin{document}

\begin{table}
\centering
\caption{Something.}
\label{tbl:4}
\begin{tabular}{
S[table-format=2.0]
@{--}    S[table-format=2.0]
S[table-format=5.0]
S[table-format=5.0]
}
\toprule
\mc{St{\o}jniveau}       & {1994} & {2005-planen} \\
\mc{\si{\decibel}}       & {---}  & {---}         \\
\midrule
55                  & 59 & 19491  & 12430         \\
60                  & 64 &  7111  &  2644         \\
65                  & 69 &  1191  &   320         \\
70                  & 74 &   280  &    43         \\
\Alignment{$> 75$}  &    &    52  &     1         \\
\bottomrule
\end{tabular}
\end{table}

\end{document}


How do I get the correct alignment in the first column?

-
Have you seen How to align numbers to en-dash in a table? –  Qrrbrbirlbel Sep 22 '13 at 15:30
@Qrrbrbirlbel No. I'll give it a try. Thanks for the pointer! –  Svend Tveskæg Sep 22 '13 at 15:32
@SvendTveskæg especially the answer there that shows how to do it if you switch back to dcolumn:-) –  David Carlisle Sep 22 '13 at 15:38
@DavidCarlisle Good point. :) –  Svend Tveskæg Sep 22 '13 at 15:42
Please keep questions in place after they got answers. If you have a new question, even a similar one, post it as such and not overwrite an existing one. –  Martin Scharrer Sep 23 '13 at 6:36

Maybe a little manual work:

Unfortunately, the \tablenum macro seems to not be made for working outside of cell (or at least not only alone in there) because the digits of the first \tablenum showed up in the second (solves by enclosing both occurence in their own group). Both also add horizontal space (probably because they’re usual an own column), this can be worked-around by using a box.

The \numtablerange syntax is made up so that one optional parameter is forwarded to both \tablenums; if however two optional arguments are given then the first one goes to the first \tablenum and the second to the second.

I thought that one could use

\numtablerange[][parse-numbers=false]{75}{\hphantom{00}}


to simulate an open-ended range but \tablenum breaks then with undefined \__siunitx_table_print_S_direct: and \__siunitx_table_print:, so I went with a even more manual approach.

By the way, if the numbers are that simple you could just use 55--59 and so on in the table directly …

## Code

\documentclass{standalone}
\usepackage{booktabs,calc}
\usepackage[locale=DE]{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}
\toprule
St{\o}jniveau                        & {1994} & {2005-planen} \\
\si{\decibel}                        & {---}  & {---}         \\ \midrule
\numtablerange{55}{59}               & 19491  & 12430         \\
\numtablerange{60}{64}               & 7111   & 2644          \\
\numtablerange{65}{69}               & 1191   & 320           \\
\numtablerange{70}{74}               & 280    & 43            \\
\makebox[\widthof{00--00}][r]{$>75$} & 52     & 1             \\ \bottomrule
\end{tabular}
\end{document}
`

## Output

-
This is great! I would never have gotten this myself. –  Svend Tveskæg Sep 22 '13 at 20:08