2

I am trying to colour certain table cells in some siunitx S columns. The cell colour change with xcolor/colortbl works, but it seems to also change the cell contents to text-mode, which has unfortunate consequences when working with siunitx and negative numbers. The coloured cells have a short text-mode minus sign while the rest stay in maths-mode with the longer minus sign. I'm not sure how to fix it. Here is an MWE and table image:

\documentclass{article}

\usepackage{siunitx}
\usepackage[table]{xcolor}
\usepackage{booktabs}

\newcommand{\blue}{\cellcolor{blue!25}}

\begin{document}

\begin{table}[]
  \begin{tabular}{
    S[table-format = 0.2]
    S[table-format = -0.2]}
    \toprule
    {A}  & {B}   \\ \midrule
    0.26 & -0.38 \\
    0.18 & \blue -0.34 \\
    \blue 0.31 & -0.36 \\ \bottomrule
  \end{tabular}
\end{table}
\end{document}

enter image description here

1 Answer 1

1

It has to be \newcommand*{\blue}{{\cellcolor{blue!25}}} with an extra set of curly braces.

1
  • 1
    @LaRiFaRi Thanks, that works perfectly! An edit with the reason it works would be great though :)
    – drgibbon
    Apr 14, 2016 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .