# Equivalent color for \colorbox{gray} as for \cellcolor[gray]{0.8}

In my table I have used \cellcolor[gray]{0.8} and I would like to mark some words in my text with the same color. I have tried \colorbox{gray}, but the resulting box in the text is too dark. How can I get the same grey-color as in the table?

• \definecolor{mygray}{gray}{0.8} and \colorbox{gray} would do the job? – yo' Apr 17 '14 at 12:55
• There are some more levels of grey in my table. Do I have to specify a separate function for each level? – DatamineR Apr 17 '14 at 12:57

The arguments to \cellcolor are just passed to \color internally so that it colours the panel of the specified colour so

\cellcolor[gray]{0.8}


just calls

\color[gray]{0.8}


and you may use that directly.

• Hello David, how shoul I use it to get the same color for the box? I have unsuccessfully tried: \colorbox{\color[gray]{0.8}}{text} – DatamineR Apr 17 '14 at 13:05
• I have tried \colorbox[gray]{0.8}{text} but the colors are not the same... – DatamineR Apr 17 '14 at 13:20
• @JohnnyB well I wrote that code and I can promise you that neither \colorbox nor \cellcolor do anything with colour values at all, both just set things up then call \color with the supplied values. – David Carlisle Apr 17 '14 at 13:25
• \colorbox{\color[gray]{0.8}}{text} no! \colorbox[gray]{0.8}{text} \colorbox is like \cellcolor and just passes its arguments to \color – David Carlisle Apr 17 '14 at 13:26

You can try gray!<percentage> syntax like gray!20

\documentclass{article}
\usepackage{xcolor}
\begin{document}
\colorbox{gray!20}{gray!20}\color{gray!80} some text
\end{document}