How to treat with dcolumn tabular format and colored rows?

by e_moro   Last Updated May 15, 2019 21:23 PM

I found here this trick for formated text coloring for use with dcolumn package. However, it seems roughly redefine the \[email protected] 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[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{xcolor,dcolumn,colortbl}

\makeatletter
\def\[email protected]{$\hfil\egroup\@dcolcolor\box\[email protected]\box\[email protected]\dcolreset}
\def\dcolcolor#1{\gdef\@dcolcolor{\color{#1}}}
\def\dcolreset{\dcolcolor{black}}
\dcolcolor{black}
\makeatother

\begin{document}

\begin{tabular}{|*{3}{D{.}{,}{1}|}}% con -1 no pasa, pero no funciona \dcolcolor
\rowcolor{gray!20}  1 & 2 & 3 \\
\rowcolor{gray!50}  -1 & 2 & 3 \\
\rowcolor{gray!20}  1 & 22 & 3 \\
%\rowcolor{gray!20} 1 & 2 & \dcolcolor{red}3.3 \\
\rowcolor{gray!20}  1 & 2 & 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 cell values

enter image description here

note: the vertical rules are just to control what's happen.



Related Questions


Updated October 13, 2017 04:23 AM

Updated January 13, 2017 01:09 AM

Updated March 08, 2017 17:23 PM

Updated December 04, 2017 16:23 PM

Updated March 10, 2019 22:23 PM