A table with fixed width columns, coloured both background and text

I am trying to create a table which has all three traits, mentioned in the title, at once. I tried tabular with individual \color for each column, tabu with \rowfont, and custom column definitions from here and here. The last method was the only one which did not cause the double row height visible in the output, yet at the same time it made the frame lines incomplete at the right side.

Is there a method, that would give a complete frame to the table, and a proper row height at once?

Input

\usepackage{color}
\usepackage{colortbl}

\definecolor{colorh}{rgb}{0.5,0.5,0.5}

\begin{document}
\begin{tabular}{ |p{2cm}|p{2cm}|p{2cm}|p{2cm}| }
\hline
\rowcolor{colorh} {\color{white}a} & {\color{white}b} & {\color{white}b} & {\color{white}d} \\
\rowcolor{colorh} e & f & g & h \\
\hline
\end{tabular}
\end{document}


Output

• I don't really unserstand what you mean with the ‘proper’ row height? – Bernard Jan 29 '16 at 21:42
• The one which is related to the height of the contents, as in the second row of the table in the example output. It has a proper height because its text has not been coloured. On the contrary, the first row has an extra space above the contents. It is not because it is the first row, as such an extra space would also be visible in any other row with coloured both background and text. – arataj Jan 29 '16 at 21:50

The problem disappears if you use the m{2cm} column type. If you want to use p{2cm}, a work around consists in using \textcolor{white}{cell contents} indtead of \color{white} cell contents:

\documentclass{article}
\usepackage[table, x11names]{xcolor}
\usepackage{hhline}
\definecolor{colorh}{rgb}{0.5,0.5,0.5}

\setlength\arrayrulewidth{0.25mm}
\newcolumntype{L}{>{\arraybackslash}p{2cm}}%

\begin{document}

\begin{tabular}{|L|L|L|L|}
\hline
\rowcolor{colorh}
\textcolor{white}{a} & \textcolor{white}{b} & \textcolor{white}{c} & \textcolor{white}{d} \\
\rowcolor{colorh}
e & f & g & h \\
\hline
\end{tabular}

\end{document}


• Is definition of your L column type complete? If it is, can you elaborate, what is its benefit of use \arraybackslash in it? – Zarko Jan 30 '16 at 0:33
• I've been used to add it for a long time. If I remember well, it is there to say \ means \tabularnewline in the last column (where it might mess up with other kinds of \, for instance if there is a maths environment like cases or align*. – Bernard Jan 30 '16 at 1:06
• So far I understood, that \arraybackslah is necessary, if you change align of cell contents. For example \newcolumntype{L}{>{\raggedright\arraybackslash}p{2cm}}. – Zarko Jan 30 '16 at 1:12
• Maybe you're right. In any case, I don't think it does any harm if used in places where it's not strictly necessary. – Bernard Jan 30 '16 at 1:30

I guess it is more of a workaround than a solution, but the last of the mentioned methods actually makes the rightmost line visible if it is specified twice, like |L|L|L|L||.

Input

\documentclass{article}
\usepackage{color}
\usepackage{colortbl}

\definecolor{colorh}{rgb}{0.5,0.5,0.5}

\setlength\arrayrulewidth{0.25mm}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{2cm}}

\begin{document}
\begin{tabular}{ |L|L|L|L|| }
\rowcolor{colorh} {\color{white}a} & {\color{white}b} & {\color{white}b} & {\color{white}d} \\
a & b & c & d \\
\rowcolor{colorh} e & f & g & h \\
\end{tabular}
\end{document}


Output

\documentclass[border=3mm]{standalone}

\usepackage[table]{xcolor}
\definecolor{colorh}{rgb}{0.5,0.5,0.5}

\begin{document}
\begin{tabular}{|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
\hline
\rowcolor{colorh}
\textcolor{white}{a}
& \textcolor{white}{b}
& \textcolor{white}{c}
& \textcolor{white}{d}      \\
e & f & g & h \\
\rowcolor{colorh}
e & f & g & h \\
\hline
\end{tabular}
\end{document}