# Colouring text in table

I have the following table:

    \documentclass[a4paper, twoside]{report}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage[T1]{fontenc}
\usepackage{dcolumn, bigdelim}
\begin{document}
\begin{table}
\centering
\begin{tabular}{*{5}{D{.}{.}{1}@{\hskip 7.5pt}}cc}
\toprule
x_1 & x_2 & x_3 & x_4 & \tabularnewline
\midrule
0.65 &  -2.26 & 0.71 & 0.97 & \rdelim\}{5}{14mm}[\parbox{20.5mm}{a}] \tabularnewline[5pt]
1.00 &  -0.25 & 0.86 & 0.57 &\tabularnewline[5pt]
-2.76 & -0.17 & 0.44 & 0.48 &\tabularnewline[5pt]
-2.76 & -0.17 & 0.44 & 0.48 &\tabularnewline[5pt]
\midrule
-2.96 & -0.17 & 0.42 & 0.48  &\rdelim\}{5}{14mm}[\parbox{20.5mm}{b}] \tabularnewline[5pt]
-3.76 & -0.17 & 0.42 & 0.48 &\tabularnewline[5pt]
-3.56 & -0.17 & 0.42 & 0.48 &\tabularnewline[5pt]
-3.76 & -0.17 & 0.42 & 0.48 &\tabularnewline[5pt]
\bottomrule
\end{tabular}
\end{table}
\end{document}


I would like to colour the text of some cells; e.g. all "0.42", how can I do that? I tried \color{red}{0.42} but it gave me some errors. Thanks for any help!

• It would be helpful if you composed a fully compilable MWE including \documentclass (you can use the article class unless the problem is specific to a given class) and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem as opposed to figuring out exactly which packages are required. – Peter Grill Aug 28 '19 at 0:15
• Yeah, you are right, sorry for that, I edited it. – Humanoid Aug 28 '19 at 0:30
• Fair point, I edited again and reframed the not-working problem into a question. – Humanoid Aug 28 '19 at 0:33
• I thought you had it working in your code though? Seems then that this problem is different than what you are encountering in your code. Anyway, you can wrap the \color{}{} within a \multicolumn so that it id not bothered by the D column type. But, this looses the alignment. – Peter Grill Aug 28 '19 at 0:35
• Isn't there an easier option with which I can just colour some letters? I am still confused why \color{}{} does not work here... – Humanoid Aug 28 '19 at 0:38

It works with S columns (defined in siunitx pacakage), however your table design is not clear. You use 4 columns for numbers and one for big delimiter (curly brace), but define 5 columns for (decimal) numbers and two more c type columns.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs, makecell} % <---
\usepackage{bigdelim}

\usepackage{siunitx}            % <---

\begin{document}
\begin{table}[ht]
\setcellgapes{3pt}
\makegapedcells
\centering
\begin{tabular}{ *{4}{S} @{\quad} c} % <---
\toprule
{$x_1$} &{$x_2$}&{$x_3$}&{$x_4$}&  \\ % <---
\midrule
0.65    & -2.26 & 0.71  & 0.97  &   $\rdelim\}{4}{3mm}[\,a]$   \\ % <---
1.00   & -0.25 & 0.86  & 0.57  &   \\
-2.76   & -0.17 & 0.44  & 0.48  &   \\
-2.76   & -0.17 & 0.44  & 0.48  &   \\
\midrule
-2.96   & -0.17 & \color{red}0.42       % <--- works fine
& 0.48  &   \\
-3.76   & -0.17 & 0.42  & 0.48  &   \\
-3.56   & -0.17 & 0.42  & 0.48  &   \\
-3.76   & -0.17 & 0.42  & 0.48  &   \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


gives:

Is this what you looking for?

• Yes, a thousand thanks! – Humanoid Aug 28 '19 at 8:54
• @user192779 Remember to accept the answer by ticking off the V at the left side of the answer. – Sveinung Aug 28 '19 at 22:05