7

I typically use the siunitx package to round numbers in tables and use the \cellcolor command of the colortbl package to change the background colors of certain cells. However, as the following example shows, they do not really go together: Only numbers in non-colored cells are rounded correctly; numbers in colored cells are not rounded.

How can I make siunitx to round numbers in the colored cells as well?

Table from example

\documentclass{beamer} 

\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{siunitx}

\begin{document}

\frame{
    \centering
    \sisetup{
        detect-mode,
        tight-spacing           = true,
        group-digits            = false,
        input-signs             = ,
        input-symbols           = ,
        input-open-uncertainty  = ,
        input-close-uncertainty = ,
        table-align-text-pre    = false,
        round-mode              = places,
        round-precision         = 3,
        table-space-text-pre    = (,
        table-space-text-post   = ),
    }
    \begin{tabular}{lSS}
        \toprule
        Cell background & {Number}                        & {Number in parentheses} \\
        \midrule
        With color      & \cellcolor{yellow!50}-.0399377* & \cellcolor{yellow!50}(.0358997) \\
        Without color   & -.030879**                      & (.0203602)                      \\
        \bottomrule
    \end{tabular}
}

\end{document}
9

You need to 'hide' the cell colour part from siunitx:

& {\cellcolor{yellow!50}} -.0399377* &

(The package can pick up simple \color commands but not at present \cellcolor ones.)

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.