Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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]
    @{\quad}
             S[table-format=5.0]
    @{\quad}
             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}

output2

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

share|improve this question
    
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
2  
@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
2  
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

1 Answer 1

up vote 3 down vote accepted

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}
  \begin{tabular}{T{table-format=2.0}{table-format=2.0}{c} @{\quad} S[table-format=5.0] @{\quad} S[table-format=5.0]}
    \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

enter image description here

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.