I found here this trick for formated text coloring for use with dcolumn package.
However, it seems roughly redefine the \DC@endright statement and gives two wrong behaviours with values which have more than one character:
1) bad vertical aligment
2) bad row color filling with \rowcolor command
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{dcolumn}
\makeatletter
\def\DC@endright{$\hfil\egroup\@dcolcolor\box\z@\box\tw@\dcolreset}
\def\dcolcolor#1{\gdef\@dcolcolor{\color{#1}}}
\def\dcolreset{\dcolcolor{black}}
\dcolcolor{black}
\makeatother
\begin{document}
\begin{tabular}{|*{3}{D{.}{,}{1}|}}
\rowcolor{gray!20} 1 & 2 & 3 \\
\rowcolor{gray!50} -1 & 2 & 3 \\
\rowcolor{gray!20} 1 & 22 & 3 \\
\rowcolor{gray!50} 1 & 2 & \dcolcolor{red}3.3 \\
\end{tabular}
\end{document}
As you can test, these issues disappear if you comment the trick lines. Nevertheless, I'd like to patch them in order to coloring values in cells.
note: the vertical rules are just to control what happens.



siunitxpackage be an option for you? – leandriis May 15 '19 at 21:20xcolorandcolortblpackages independently of each other. Instead, run the single instruction\usepackage[table]{xcolor}. – Mico May 22 '19 at 11:09Scolumn type cannot be embedded in a loop command, whereas theDcolumn type can. Can you elaborate on that? – Mico May 23 '19 at 05:53Dcolumn type works correctly whereas theScolumn type does not. – Mico May 23 '19 at 15:04