# Why does adding color to a table row increase the height?

I'm trying to make a beamer slide containing a table with the text in a row styled in a different color. However, the row's height increases when colored, as opposed to the default. The same problem occurs if I use the \rowfont command. How do I correct this?

\PassOptionsToPackage{table}{xcolor}
\documentclass[compress]{beamer}

\begin{document}
\begin{frame}
Example 1
\rowcolors{1}{gray!30}{blue!30}
\begin{tabular}{|p{0.5\textwidth}|}
\hline
\color{blue}{Foo} \\
Bar\\
Baz\\
\hline
\end{tabular}\\[1in]

Example 2
\rowcolors{1}{gray!30}{blue!30}
\begin{tabular}{|p{0.5\textwidth}|}
\hline
Foo \\
Bar\\
Baz\\
\hline
\end{tabular}
\end{frame}
\end{document}


I want the table to look like "Example 2", but with the row text colored as in "Example 1".

• Does \leavevmode (before or after \color) help? I remember a similar case. Oct 14, 2013 at 7:29
• See the footnote on page 5 of texdoc grfguide (Using textcolor or putting \leavevmode or mbox{} before \color will fix it. (Sorry, it's not my fault:) Oct 14, 2013 at 10:18
• @DavidCarlisle This comment was difficult to find. It deserves to be more than a comment. I have scratched my head the whole day, trying to solve a similar problem. Nov 6, 2014 at 18:34

Use textcolor:

\PassOptionsToPackage{table}{xcolor}
\documentclass[compress]{beamer}

\begin{document}
\begin{frame}

Example 1
\rowcolors{1}{gray!30}{blue!30}
\begin{tabular}{|p{0.5\textwidth}|}
\hline
\textcolor{blue}{Foo} \\
Bar\\
Baz\\
\hline
\end{tabular}\\[1in]

Example 2
\rowcolors{1}{gray!30}{blue!30}
\begin{tabular}{|p{0.5\textwidth}|}
\hline
Foo \\
Bar\\
Baz\\
\hline
\end{tabular}
\end{frame}
\end{document}


With {NiceTabular} of nicematrix, you have directly the expected output.

\documentclass[compress]{beamer}
\usepackage{nicematrix}

\begin{document}
\begin{frame}
\begin{NiceTabular}{|p{0.5\textwidth}|}
\CodeBefore
\rowcolors{1}{gray!30}{blue!30}
\Body
\hline
\color{blue}{Foo} \\
Bar\\
Baz\\
\hline
\end{NiceTabular}
\end{frame}
\end{document}


You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).