[Tex/LaTex] Table – align according decimal comma

tables

How can I align numbers in table according to the decimal comma please when I don't know how many numbers are befor the comma and how many decimal places the number will have?

\documentclass[12pt,a4paper]{report}
\usepackage[english,czech]{babel}
\usepackage[margin=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern,textcomp}
\usepackage{amsmath, amssymb, bm}
\usepackage[nottoc]{tocbibind}
\usepackage{icomma,dcolumn,booktabs}

\newcommand{\mc}[1]{\multicolumn{1}{c}{#1}}
\usepackage{tabularx, ragged2e}
\newcolumntype{d}[1]{D{.}{,}{#1}}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\begin{document}

\begin{table}\small
\setlength\tabcolsep{3pt}
\begin{tabularx}{\textwidth}{@{} L *{8}{c} @{}}
\toprule
Číslo & $P$ & $T_0$ & $e$ & $\omega$ & $i$ & $a$  \\[0.33ex]
zdroje& (dny) & (RJD) & & ($^\circ$) & ($\mathrm{M}_{\odot}$) & ($\mathrm{M}_{\odot}$) \\
\midrule
1 & 5,732436(15) & 54002,780(46) & 0,0910(37) & 149,2(3,0) &  &  \\
2 & 5.732824(3) & 54002,7241(96) & 0,0858(41) & 145,6(3,9) && \\
3 & 5.732824(1) & 54002,7775(34) & 0,0883(26) & 149,1(2,3) && \\
\bottomrule
\addlinespace

\end{tabularx}
\end{table}
\end{document}

enter image description here

Best Answer

with siunitx and makecell packages:

enter image description here

in your mwe you have mess in use of decimal points and commas. i decide to use decimal points. if you like to have commas in resulting table, than you need to add in preamble:

\sisetup{output-decimal-marker={,}}

also your use of uncertainty (with commas) is not clear. such notation is not supported in the siunitx pacakage (as far as i know).

\documentclass[12pt,a4paper]{report}
\usepackage{booktabs, makecell}
\usepackage{siunitx}

\begin{document}
    \begin{table}[htb]
    \small
    \setlength\tabcolsep{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} 
                            c
                            S[table-format=1.6(2)]
                            S[table-format=5.3(2)]
                            S[table-format=1.4(2)]
                            S[table-format=3.1(2)]
                            cc % for those columns is not clear what is in them
                            }
    \toprule
\makecell[t]{Číslo\\ zdroje}
    &   {\makecell[t]{$P$\\ (dny)}}
        &   {\makecell[t]{$T_0$\\ (RJD)}}
            &   {\makecell[t]{$e$}}
                &   {\makecell[t]{$\omega$\\ (\si{\degree})}}
                    &   {\makecell[t]{$i$\\ ($\mathrm{M}_{\odot}$)}}
                        &   {\makecell[t]{$a$\\ ($\mathrm{M}_{\odot}$)}}    \\
    \midrule
1 & 5.732436(15) & 54002.780(46)  & 0.0910(37) & 149.2(30) &   &            \\
2 & 5.732824(3)  & 54002.7241(96) & 0.0858(41) & 145.6(39) &   &            \\
3 & 5.732824(1)  & 54002.7775(34) & 0.0883(26) & 149.1(23) &   &            \\
    \bottomrule
\end{tabular*}
    \end{table}
\end{document}
Related Question