I can use colortbl to color the background of a row by setting \rowcolor{Gray}. How can I set only the text to gray and keep the white background instead?
Asked
Active
Viewed 3,113 times
2
sodiumnitrate
- 1,257
-
2This is similar to setting a "row style" which would affect the "foreground elements". As such, see [An improved `\rowstyle that takes the cell contents as an argument](https://tex.stackexchange.com/q/32861/5764) (possible duplicate). – Werner Jan 31 '18 at 05:38
1 Answers
4
A solution with a code borrowed to an answer to a question I can't find:
\documentclass[11pt]{article}%
\usepackage[table, svgnames]{xcolor}
\usepackage{array}
\makeatletter
\g@addto@macro{\endtabular}{\rowfont{}}% Clear row font
\makeatother
\newcommand{\rowfonttype}{}% Current row font
\newcommand{\rowfont}[1]{% Set current row font
\gdef\rowfonttype{#1}#1\ignorespaces%
}
\makeatother
\begin{document}
\setlength{\extrarowheight}{3pt}
\begin{tabular}{*{5}{>{\rowfonttype}c}<{\rowfont{}}}
\hline
A & B & C & D & E \\
\hline
\rowcolor{WhiteSmoke}\rowfont{\color{Tomato}} I & II & III & IV & V \\
\hline
a & b & c & d & e\\
\hline
\end{tabular}
\end{document}
If you want a table with vertical rules, it's slightly different to return to non-coloured text in the next row:
\begin{tabular}{|*{5}{>{\rowfonttype}c|}}
\hline
A & B & C & D & E \\
\hline
\rowcolor{WhiteSmoke}\rowfont{\color{Tomato}} I & II & III & IV & V \\
\hline
\rowfont{\color{black}}a & b & c & d & e\\
\hline
\end{tabular}
Bernard
- 271,350
-
Thanks! How can I add vertical lines between the columns with this? – sodiumnitrate Jan 31 '18 at 15:22
-
The code will be slightly different in this case. I've added this case, pleease take a look. I don't recommend it, though, as the table will look terribly non-professional. – Bernard Jan 31 '18 at 15:44

