[Tex/LaTex] Align siunitx columns in numbers table

columnssiunitxtablesvertical alignment

Here is a table but it has a problem: the column of 1, 20, 50, and 100 aren't perfectly aligned to others. How can I do that?

MWE

\documentclass{article}
\usepackage{siunitx,booktabs,multirow}
\begin{document}
\begin{table}[htp]
    \centering
    \begin{tabular}{lS[table-format=4.5]
                     S[table-format=4.5]
                     S[table-format=4.5]
                     S[table-format=4.5]}
        \toprule
        \multirow{2}*{\textsc{PEP}} &     \multicolumn{4}{c}{Nodi}     \\ \cmidrule(lr){2-5}
                                    & 1      & 20     & 50     & 100    \\ \midrule
        1e-06                       & 1      & 1      & 1      & 1.0001 \\
        1e-05                       & 1      & 1.0002 & 1.0005 & 1.001  \\
        0.0001                      & 1.0001 & 1.002  & 1.005  & 1.0099 \\
        0.001                       & 1.001  & 1.0198 & 1.0486 & 1.0952 \\
        0.01                        & 1.01   & 1.1846 & 1.4    & 1.6447 \\
        0.1                         & 1.1111 & 2.084  & 2.4454 & 2.7404 \\ \bottomrule
    \end{tabular}
\end{table}
\end{document}

enter image description here

Best Answer

The format for the S columns should reflect the actual values. For centering the header one could use \multicolumn{1}{c}{...}, but just enclosing the value in braces stops siunitx to use the alignment of numbers and use the default, which is centering (thanks to Qrrbrbirlbel for noting it)

\documentclass{article}
\usepackage{siunitx,booktabs}
\begin{document}
\begin{tabular}{lS[table-format=1.4]
                 S[table-format=1.4]
                 S[table-format=1.4]
                 S[table-format=1.4]}
\toprule
PEP & \multicolumn{4}{c}{Nodi} \\
\cmidrule(lr){2-5}
            &   {1}  &  {20}   &  {50}  & {100}  \\
\midrule
\num{1e-06} & 1      & 1       & 1      & 1.0001 \\
\num{1e-05} & 1      & 1.0002  & 1.0005 & 1.001  \\
\num{0.0001}& 1.0001 & 1.002   & 1.005  & 1.0099 \\
\num{0.001} & 1.001  & 1.0198  & 1.0486 & 1.0952 \\
\num{0.01}  & 1.01   & 1.1846  & 1.4    & 1.6447 \\
\num{0.1}   & 1.1111 & 2.084   & 2.4454 & 2.7404 \\
\bottomrule
\end{tabular}
\end{document}

There is no need to use \multirow; I believe that placing "PEP" next to the horizontal rule ruins the table. Of course \textsc does nothing to it.

enter image description here

Related Question