Display standard deviation below value in tabularx with siunitx

siunitxtablestabularxvertical alignment

I am trying to display in a table the standard deviation below the value in brackets. For the alignment of the numbers I use siunitx. Since I have some long descriptions in the first column, I use tabularx.

Currently I write the standard deviation for each value in a new row. For short descriptions in the first column it works. However, for long descriptions, the standard deviation is displayed well below the value.

Does anyone have an idea how I can display the standard deviation in a different way just below the value so that it displays correctly for long descriptions?

Below is a minimum working example and an image of the output.

For clarification, since I have a lot of tables in my document, I abbreviate the input of the value and associated significance (a,b,c) with \vsig and the input of the standard deviation with associated brackets () with \sd defined in the preamble.

Many thanks in advance!

\documentclass[a4paper, captions=tableheading, titlepage,bibliography=totocnumbered]{scrartcl}


% Tabelle 
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{array}
\usepackage[locale=DE]{siunitx}

% Value and Significance
\newcommand{\vsig}[2]{#1\textsuperscript{ {#2}}}

% Standard deviation
\newcommand{\sd}[1]{{(}#1{)}}


\begin{document}
    

\begin{table}[htbp]
    {\centering \small
    \sisetup{
  input-symbols         = (),
  table-format          = 1.2,
  table-space-text-post = \textsuperscript{ {a}},
  table-space-text-pre  = ~,
  table-align-text-post = false,
  table-align-text-pre  = false,
  table-auto-round} 
    \caption{Caption}


    \begin{tabularx}{\linewidth}{>{\raggedright\arraybackslash}XSSSS}

    \toprule
    & {Cluster (1)} & {Cluster (2)} & {Cluster longname(3)} & {Total} \\
    \midrule
    
Short text & \vsig{4,35}{a} & \vsig{2,74}{b} & \vsig{1,32}{c} & \num{2,65} \\
    
            &   \sd{0,781} & \sd{0,818} & \sd{0,499} & \sd{1,353} \\
    
Very long text very long text very long text & \vsig{4,79}{a} & \vsig{3,75}{b} & \vsig{2,69}{c} & \num{3,65} \\
    
            & \sd{0,629} & \sd{0,957} & \sd{0,943} & \sd{1,188} \\
    
\bottomrule

    \end{tabularx} }
\end{table}


\end{document}

Output

Best Answer

If it's ok to assume that the "long text" in the header column never spans more than 2 consecutive rows, the following solution may be of interest to you. (Aside: If the "long text" spans more than two rows, you should probably make it a priority to shorten the "long text".) The solution works by encasing the long texts in the header column in \mytab directives, where \mytab is defined below. Observe the use of hanging indentation.

enter image description here

\documentclass[a4paper, captions=tableheading, titlepage,
               bibliography=totocnumbered]{scrartcl}

% Tabelle 
\usepackage{booktabs,tabularx}
\usepackage[locale=DE]{siunitx}

% Value and Significance
\newcommand{\vsig}[2]{#1\textsuperscript{ {#2}}}
% Standard deviation
\newcommand{\sd}[1]{{(}#1{)}}

% new code:
\usepackage{array,amsmath,ragged2e}
\newcolumntype{L}{>{\RaggedRight}X}
\newcolumntype{P}{>{\RaggedRight\hangafter=1\hangindent=1em}p{\hsize}}
\newcommand\mytab[1]{\smash[b]{\begin{tabular}[t]{@{}P@{}} #1 \end{tabular}}}

\begin{document}
    
\begin{table}[htbp]
%% \centering  % redundant
\small
\sisetup{
  input-symbols         = (),
  table-format          = 1.2,
  table-space-text-post = \textsuperscript{ {a}},
  table-space-text-pre  = ~,
  table-align-text-post = false,
  table-align-text-pre  = false,
  table-auto-round} 
\caption{Caption}

\begin{tabularx}{\linewidth}{LSSSS}
    \toprule
    & {Cluster (1)} & {Cluster (2)} & {Cluster longname(3)} & {Total} \\
    \midrule  
    Short text & \vsig{4,35}{a} & \vsig{2,74}{b} & \vsig{1,32}{c} & \num{2,65} \\   
               &   \sd{0,781} & \sd{0,818} & \sd{0,499} & \sd{1,353} \\   
    \mytab{Very long text very long text very long text} 
               & \vsig{4,79}{a} & \vsig{3,75}{b} & \vsig{2,69}{c} & \num{3,65} \\   
               & \sd{0,629} & \sd{0,957} & \sd{0,943} & \sd{1,188} \\   
    \bottomrule
\end{tabularx} 
\end{table}

\end{document}