# How to center numbers beneath a \multicolumn row in a table

I am making tables containing a column with number intervals, i.e. two numbers separated with a "--" or a single number preceded with a "<" or a ">". I have tried to center the position of the "--", "<" or ">" symbols by means of adding @{} into the tablular environment, see code below. However, even thought the "--", "<" or ">" symbols line up vertically this way, they do not center relative to a three-column heading above ("Damage Interval"). How do I make the symbols center horizontally relative to their heading ?

To make it easier to see the position of the @{} commands relative to the column descriptors ("l", "c" and "r") I have added vertial lines between the numbers and the "--", "<" or ">" symbols.

\documentclass[10pt,a4paper,twosided]{article}
\begin{document}
\begin{table}[h]
\centering
\caption{My caption}
\begin{tabular}[h]{l |  r @{} |  @{}c@{} |  @{}  l  |  c}
\hline
&\multicolumn{3}{c|}{year} &     \hline
Les           & 0.1&--&1       & com. a\\
Moderae       &   1&--&3       & com. b\\
Considerable  &   3&--&10      & com. c\\
Serious       &    &$>$&10     & com. d\\
\hline
\end{tabular}
\label{tab-label}
\end{table}
\end{document}

-

(Improved version.) Initially, I had proposed to assign all columns an automatically determined width, i.e. define them as tabu X columns. The number columns were defined as encapsulated siunitx S columns. However, this approach required balancing the relative widths of the X columns, which actually is not necessary.

It's more natural (and requires less effort) to let all columns determine their width based on their content*, and insert two additional empty X columns to center the three inner columns. Their width may either be indirectly determined by specifying a total width for the table (see comment in code), or, as in the example, be directly set by using tabu's spread feature, which tells the columns to be <dimension> wider than their natural width. The header multicolumn now spans five columns, and since the two empty X columns are of equal width, the three inner data columns are centered. As a minor drawback, in comparison to the previous version two additional ampersands per row are required.

\documentclass[10pt,a4paper,twosided]{article}

\usepackage{tabu}
\usepackage{siunitx}    %number alignment
\usepackage{booktabs}   %prettify
\renewcommand{\arraystretch}{1.25}  %increase spacing
\begin{document}

\begin{table}[h]
\centering
\caption{My caption}
\vspace{\defaultaddspace}   %a space defined by booktabs
%X columns are spread 1em wider than their natural width
%if "spread 1em" is replaced by "to .7\textwidth", instead the width of the table would be specified and the X columns would stretch accordingly.
S[table-format=2.1] %number format with one decimal
c
S[table-format=2.1] %same number format to keep column width equal
c}
\toprule
Category&\multicolumn{5}{c}{Damage Interval Year} & Comments \\\toprule
Les           && 0.1&--&1       && com. a\\
Moderae       &&   1&--&3       && com. b\\
Considerable  &&   3&--&10      && com. c\\
Serious       &&    &$>$&10     && com. d\\
\bottomrule
\end{tabu}
\label{tab-label}
\end{table}

\end{document}


*Should some content however require line breaks, then the use of X columns for these columns might be advisable.

-
Thanks :) I will try this –  Espen Donali Jun 11 '12 at 14:47
@EspenDonali There's an improved solution now. –  dgs Jun 11 '12 at 18:59
Thanks, I haven't tried your solution yet, but regarding your last solution, there is much space between the numbers in each interval and the central symbol in the interval ("--" OR "<" OR ">"). For instance, 0.01 -- 1. Do your solution let me shrink this distance between the numbers and the central symbol? –  Espen Donali Jun 12 '12 at 9:30
Yes. You've used @{} to define empty intercolumn spaces in your original code, and you can apply the same method in my solution. Zero intercolumn space looks somewhat ugly, so you'd probably rather use something like @{\hspace{1ex}}. You can visualize what's going on by inserting vertical bars |. –  dgs Jun 12 '12 at 9:59
Sorry to bother you with this, but it is not clear for me where to put these @{\hspace{1ex}} commands. Do I put them inside the tabu environment? –  Espen Donali Jun 12 '12 at 10:27

If a spanning entry is wider than the columns it spans, TeX puts all the extra width in the last column. So normally you need to avoid that happening, which usually is not as nice as one might wish.

Here you could do

which pads the empty cell with half the width of the heading minus the width of --

\documentclass[10pt,a4paper,twoside]{article}
\begin{document}
\begin{table}[h]
\centering
\caption{My caption}
\begin{tabular}[h]{l |  r @{} |  @{}c@{} |  @{}  l  |  c}
\hline
&\multicolumn{3}{c|}{year} &     \\
\hline
Les           & 0.1&--&1       & com. a\\
Moderae       &   1&--&3       & com. b\\
Considerable  &   3&--&10      & com. c\\
Serious       &
\setbox0\hbox{Damage Interval}%
\setbox2\hbox{--}%
\dimen0\wd0
\mbox{}\kern0.5\dimen0   &$>$&10     & com. d\\
\hline
\end{tabular}
\label{tab-label}
\end{table}
\end{document}


Note I had to fix some other unrelated errors in the MWE to avoid errors and warnings.

-
Thanks a lot! But I do not understand why all the new code you added are added inside the last row in the table, that one starting with "Serious". Is it possible to rewright the added code so that it can be placed before the table-rows? –  Espen Donali Jun 11 '12 at 11:41
I added it there as that was a convenient empty cell. You can add it anywhere in that column but if the cell is non empty you have to work a bit harder to allow for the width of the entry. You could for example put it in the first row after the heading followed by \llap{$0.1$}  so that the 0.1 that is there takes up no space itself and overlaps the padding space added. –  David Carlisle Jun 11 '12 at 11:48
@DavidCarlisle Nice. –  dgs Jun 11 '12 at 11:49
Hm, thanks :) , your code works well in the minimum working example above, but when I put it into the context where I want to use it, it still gives intervals not centered below the heading. –  Espen Donali Jun 11 '12 at 14:44
it should work (so long as the heading text is what is causing the extra space) try to make a less minimal example that shows the problem –  David Carlisle Jun 11 '12 at 14:46