6

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

1
  • Please, always add the packages necessary to typeset the example.
    – egreg
    Dec 23 '12 at 22:25
8

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

3
  • 3
    There’s no need to use \multicolum, if the cell’s content is enclosed in braces, it is not typset as a number but as text according to the table-text-alignment option (default: center). Dec 23 '12 at 22:28
  • @Qrrbrbirlbel Really! Nice to learn something new!
    – egreg
    Dec 23 '12 at 22:29
  • 6
    @Qrrbrbirlbel there should be a badge for teaching egreg something new :)
    – cmhughes
    Dec 23 '12 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.