Correctly use table-align-text-post and table-number-alignment

alignmentsiunitxtables

I want to create a simple table using the siunitx package.
The right column of the table should look like this:

  • The T should be centered above everything, which comes below
  • The numbers and text below should be aligned individually
  • The numbers should be aligned at their decimal point
  • The text should be left aligned

After reading the user guide of siunitx I thought the two fitting commands would be:
"table-number-alignment = center" to center the T above everything else and
"table-align-text-post = true" to align the text (centered and not left aligned, but could be figured out later).
The alignment on the decimal point is already a default

Lets look at the results:

\documentclass[12pt,a4paper,twoside]{scrreprt} 

\usepackage{amsmath} 
\usepackage{amssymb}
\usepackage[english]{babel}
\usepackage{hhline}
\usepackage{siunitx}

\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\renewcommand{\arraystretch}{2}

\begin{document} % Dokument beginnen

\sisetup{table-align-text-post = true}
\begin{table}[t!]
\begin{center}
\begin{tabular}{@{}C{0.25\textwidth}@{}S[table-column-width = 0.25\textwidth]@{}}
\hline\hline
 {Type} & {T} \\
\hhline{--}
1 & 2.222 \textsuperscript{a} \\
2 & 3.333 \textsuperscript{b} \\
3 & 4.444 \textsuperscript{c} \\
4 & 5.555 \textsuperscript{d}  \\
5 & 6.66  \textsuperscript{e}  \\
\hline\hline
\end{tabular}
\end{center}
\end{table}

\sisetup{table-number-alignment = center,table-align-text-post = true}
\begin{table}[t!]
\begin{center}
\begin{tabular}{@{}C{0.25\textwidth}@{}S[table-column-width = 0.25\textwidth]@{}}
\hline\hline
 {Type} & {T} \\
\hhline{--}
1 & 2.222 \textsuperscript{a} \\
2 & 3.333 \textsuperscript{b} \\
3 & 4.444 \textsuperscript{c} \\
4 & 5.555 \textsuperscript{d}  \\
5 & 6.66  \textsuperscript{e}  \\
\hline\hline
\end{tabular}
\end{center}
\end{table}

\end{document}

enter image description here

Somehow table-align-text-post = true does not align the post-text on its own and if table-number-alignment = center is used it aligns the post-text, but it overlaps with the numbers. My first idea was, that the overlapping can be avoided by choosing the correct value for table-format, but this does not work. Also the T is not centered above the number in any of the cases.

Best Answer

Welcome to TeX.SE!

  • your last demand is no clear. Which text you like to have left aligned?
  • don't use center environment in table float. It add spurious vertical space. Instead it rather use \centering command after \begin{table}` as is done in MWE (Minimal Working example) below.
  • default positioning of text in S columns is center
  • you need to define numbers format. In this you need to reserve space for notes (exponents) at numbers (see MWE below)
  • Instead of hhline I would rather use bootabs rules as are in the second example.
  • Due to added exponents to numbers, I guessing, that you like to add (latter) table notes. IN this case you see `threparttable´. This may help you.
\documentclass[12pt,a4paper,twoside]{scrreprt}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[english]{babel}
\usepackage{booktabs,
            hhline}
\usepackage{siunitx}

\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\renewcommand{\arraystretch}{2}

\begin{document} % Dokument beginnen

\begin{table}[t!]
\sisetup{table-format=1.3{*},
         table-align-text-after=false}
\centering
\begin{tabular}{@{} C{0.25\textwidth} S[table-column-width = 0.25\textwidth] @{}}
    \hhline{==} % <--- changed
Type    &   {T} \\
    \hhline{--}
1   & 2.222 \textsuperscript{a} \\
2   & 3.333 \textsuperscript{b} \\
3   & 4.444 \textsuperscript{c} \\
4   & 5.555 \textsuperscript{d}  \\
5   & 6.66  \textsuperscript{e}  \\
    \hhline{==}
\end{tabular}

\bigskip
\begin{tabular}{@{} C{0.25\textwidth} S[table-column-width = 0.25\textwidth] @{}}
    \toprule
Type    &   {T} \\
    \midrule
1   & 2.222 \textsuperscript{a} \\
2   & 3.333 \textsuperscript{b} \\
3   & 4.444 \textsuperscript{c} \\
4   & 5.555 \textsuperscript{d}  \\
5   & 6.66  \textsuperscript{e}  \\
    \bottomrule
\end{tabular}
\end{table}

\end{document}

Are above results what you after?

enter image description here

Addendum: You may consider write table with use of the tabularray package:

\documentclass[12pt,a4paper,twoside]{scrreprt}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document} 
    \begin{table}[t!]
\sisetup{table-format=1.3{*},
         table-align-text-after=false}
\centering
\begin{tblr}{ width=0.5\textwidth,
            colspec={@{} X[c] X[c, si] @{}},
            row{1} ={guard}
            }
    \toprule
Type    &   {T} \\
    \midrule
1   & 2.222 \textsuperscript{a} \\
2   & 3.333 \textsuperscript{b} \\
3   & 4.444 \textsuperscript{c} \\
4   & 5.555 \textsuperscript{d} \\
5   & 6.66  \textsuperscript{e} \\
    \bottomrule
\end{tblr}
\end{table}

\end{document}

enter image description here