[Tex/LaTex] Dot-aligned table column with defined width

arrayscolumnshorizontal alignmenttabularx

I am trying to specify a custom column command, taking a width parameter and aligning the column by the decimal point of the content.


I am using the tabularx package to use columns with a pre-defined width

p{<width>}

The width is corrected by table margins with my defined \COLW{<width>} command (see Table layout with tabularx (column widths: 50%|25%|25%) for reference)

What I am trying to achieve is a columend aligned along the decimal dot, which is provided by the 'S' column option of the siunitx. But this does not allow to specify the column width. I found the array package providing the \centerdots and \endcenterdots commands to define this behavior manually with a custom column type 'd' like

\newcolumntype{d}[1]{>{\centerdots\arraybackslash}p{#1}<{\endcenterdots}} 

But somehow these commands are not properly recoginzed

undefined control sequence [...] \centerdots

Any ideas how to combine dot-aligned columns with explicit width specifications?


Minimal working example

\documentclass[a4paper,11pt]{report}

\usepackage{array}      %should provide \centerdots command!?
\usepackage{tabularx}   %tabularx environment with fixed size columns
\usepackage{ragged2e}   %Provide \RaggedLeft and \RaggedRight commands
\usepackage{siunitx}    %Add 'S' option in tables to align along decimal point

\newcommand{\COLW}[1]{\dimexpr#1\textwidth-2\tabcolsep-1.3333\arrayrulewidth} %defined column width with margin correction
\newcolumntype{R}[1]{>{\RaggedLeft\arraybackslash}p{#1}} %right-aligned column with given column width
\newcolumntype{L}[1]{>{\RaggedRight\arraybackslash}p{#1}} %left-aligned column with given column width
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} %centered column with given column width
\newcolumntype{d}[1]{>{\centerdots\arraybackslash}p{#1}<{\endcenterdots}} %dot-aligned column with given column width

\begin{document}

\begin{table}[hbtp!]
  \centering
  %this setup uses the 'S' column from siunitx package which properly centeres the content along the dot, BUT does not allow for column width specification
  \begin{tabularx}{1.0\textwidth}{|L{\COLW{0.25}}|C{\COLW{0.25}}|R{\COLW{0.25}}|d{\COLW{0.25}}|}
  %this setup uses \centerdots command from array package and defined column width, but doesn't work
  %\begin{tabularx}{1.0\textwidth}{|L{\COLW{0.25}}|C{\COLW{0.25}}|R{\COLW{0.25}}|S|}
    \hline
    left-aligned & centered & right-aligned & \multicolumn{1}{c|}{dot-aligned} \\ %multicolumn as workaround for non decimal number conflicting with 'S' option
    \hline 
    1 & 1 & 1 & 100.0   \\
    2 & 2 & 2 &  10.0   \\
    3 & 3 & 3 &   1.0   \\
    4 & 4 & 4 &   0.1   \\
    5 & 5 & 5 &   0.01  \\
    6 & 6 & 6 &   0.001 \\
    \hline  
  \end{tabularx}    
\end{table}

\end{document}

Best Answer

You can not use tabularx unless you specify at least one X column to allow it to stretch that column to achieve the stated width.

Here I would just use siunitx (or dcolumn) and control the column widths by specifying (larger) formats for the numbers if that is required, for example the following where two of the columns have been forced wider.

enter image description here

\documentclass[a4paper,11pt]{report}

\usepackage{array}      %should provide \centerdots command!?

\usepackage{ragged2e}   %Provide \RaggedLeft and \RaggedRight commands
\usepackage{siunitx}    %Add 'S' option in tables to align along decimal point

\begin{document}

\begin{table}[hbtp!]
  \centering
  \begin{tabular}{SSS[table-format=6.2]S[table-format=4.4]}
    \hline 
    1 & 1 & 1 & 100.0   \\
    2 & 2 & 2 &  10.0   \\
    3 & 3 & 3 &   1.0   \\
    4 & 4 & 4 &   0.1   \\
    5 & 5 & 5 &   0.01  \\
    6 & 6 & 6 &   0.001 \\
    \hline  
  \end{tabular} 

\bigskip

or to a specified width

\bigskip

  \begin{tabular*}{.9\textwidth}{
@{\extracolsep{\fill}}
SSS[table-format=6.2]S[table-format=4.4]
@{}}
    \hline 
    1 & 1 & 1 & 100.0   \\
    2 & 2 & 2 &  10.0   \\
    3 & 3 & 3 &   1.0   \\
    4 & 4 & 4 &   0.1   \\
    5 & 5 & 5 &   0.01  \\
    6 & 6 & 6 &   0.001 \\
    \hline  
  \end{tabular*} 

\end{table}

\end{document}