# Problem aligning decimals in multi-column table

I've created a multi-column table with headers above each column (abridged table presented in code below). I am trying to align on the decimal point, which I've succeeded in doing using the siunitx package.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{siunitx} %%aligns by decimal points: https://tex.stackexchange.com/questions/2746/aligning-numbers-by-decimal-points-in-table-columns
\usepackage[singlelinecheck=false]{caption}
\usepackage{array}
\usepackage[document]{ragged2e}
\sisetup{
input-symbols = {()},
group-digits  = false,
explicit-sign
}
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\setlength{\tabcolsep}{8pt}
\hspace*{-2.5cm}
\begin{tabular}{@{}l
*{6}{S[table-format=-3.1]}@{}}
\toprule
& \multicolumn{3}{c}{ROC}      &
\multicolumn{3}{c}{Quebec}   \\
\cmidrule(lr){2-4}\cmidrule(lr){5-7}
Variables                                & Married & Cohabiting & Total &
Married & Cohabiting & Total \\ \midrule
Age difference^{ab}                   &         &            &       &
&            &       \\
\quad 0-1 years                          & 36.4    & 26.3       & 35.3  &
40.7    & 28.1       & 34.9  \\
\quad Woman older (2+ years)                   & 11.3    & 17.0       & 11.9
& 10.3    & 11.9       & 11.0  \\
\quad Man older (2-4 years)                    & 27.6    & 28.8       & 27.8
& 24.0    & 37.8       & 30.3  \\
\quad Man older (5+ years)                     & 24.7    & 27.9       & 25.1
& 25.1    & 22.2       & 23.8  \\ \bottomrule
\end{tabular}
\end{table}

\end{document}


However, the table's headers get wonky when my code is like this, as pictured below.

When I try to fix that, I end up undoing how the decimal points are lined up. I've tried to fix it by 1) adding back "cccccc" into the line after \begin{tabular} or using "table-number-alignment=center" on the line where I specify the number of digits for alignment of the decimal points.

I've read quite a few questions on this subject already, but none of the solutions seem to be working. I'm admittedly quite new to LaTeX, so I apologize if there is an easy answer!

Any help is greatly appreciated! Thank you.

## 1 Answer

Is it like you want?

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{booktabs}
\usepackage{siunitx} %%aligns by decimal points: https://tex.stackexchange.com/questions/2746/aligning-numbers-by-decimal-points-in-table-columns
\usepackage[singlelinecheck=false]{caption}
\usepackage{array}
\usepackage[document]{ragged2e}
\sisetup{
input-symbols = {()},
group-digits = false,
explicit-sign
}

\begin{document}

\begin{table}[!htb]
\centering\captionsetup{margin = 2.5cm}
\caption{My caption}
\label{my-label}
\setlength{\tabcolsep}{8pt}
\captionsetup{margin=2.5cm}
\begin{tabular}{@{}l
*{6}{S[table-format=2.1,table-number-alignment=center]}@{}}
\toprule
& \multicolumn{3}{c}{ROC} &
\multicolumn{3}{c}{Quebec} \\
\cmidrule(lr){2-4}\cmidrule(lr){5-7}
{Variables} & {Married} & {Cohabiting} & {Total} &
{Married} & {Cohabiting} & {Total} \\ \midrule
Age difference$^{ab}$ \\[0.5ex]
\quad 0--1 years & 36.4 & 26.3 & 35.3 &
40.7 & 28.1 & 34.9 \\
\quad Woman older (2+ years) & 11.3 & 17.0 & 11.9
& 10.3 & 11.9 & 11.0 \\
\quad Man older (2--4 years) & 27.6 & 28.8 & 27.8
& 24.0 & 37.8 & 30.3 \\
\quad Man older (5+ years) & 24.7 & 27.9 & 25.1
& 25.1 & 22.2 & 23.8 \\ \bottomrule
\end{tabular}
\end{table}

\end{document}


• showframe option shows precisely that table exceeds left margin. – skpblack Aug 16 '17 at 1:54
• Unfortunately, not. This is what I tried earlier, but the table headers of "married" and "cohabiting" still come out warped. – daha93 Aug 16 '17 at 12:36
• Could you post the exact code you tried? – Bernard Aug 16 '17 at 12:46