Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
Please, always add the packages necessary to typeset the example. –  egreg Dec 23 '12 at 22:25
add comment

1 Answer

up vote 7 down vote accepted

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

share|improve this answer
2  
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). –  Qrrbrbirlbel Dec 23 '12 at 22:28
    
@Qrrbrbirlbel Really! Nice to learn something new! –  egreg Dec 23 '12 at 22:29
3  
@Qrrbrbirlbel there should be a badge for teaching egreg something new :) –  cmhughes Dec 23 '12 at 22:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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