# How to highlight table rows by colors in Beamer

I would like to highlight rows in tables, in rowwise, that is I would like to highlight row 1 in red, then make row 1 in black but row 2 in red, etc.

How can I manage to do so in Beamer?

-
like this: tables-colouring-odd-even-mix? –  cmhughes Aug 23 '12 at 4:11

For a simple customized static row colouring :

\documentclass{beamer}
\usepackage{color, colortbl}
\definecolor{LRed}{rgb}{1,.8,.8}
\definecolor{MRed}{rgb}{1,.6,.6}
\definecolor{HRed}{rgb}{1,.2,.2}
\begin{document}
\begin{frame}
\begin{tabular}{ccc}
\rowcolor{LRed} a & b & c \\
a & b & c \\
\rowcolor{LRed} a & b & c \\
\rowcolor{MRed} a & b & c \\
\rowcolor{HRed} a & b & c \\
\rowcolor{MRed} a & b & c \\
\rowcolor{LRed} a & b & c \\
\rowcolor{MRed} a & b & c \\
\end{tabular}
\end{frame}
\end{document}


For overlays of odd/even coloring of the link of cmhughes or some more complex, see this MWE:

    \documentclass[xcolor=table]{beamer}

\rowcolors{1}{gray!30}{gray!10}

\makeatletter
\def\rowcolor{\noalign{\ifnum0=}\fi\bmr@rowcolor}
\newcommand<>{\bmr@rowcolor}{%
\alt#1%
{\global\let\CT@do@color\CT@@do@color\@ifnextchar[\CT@rowa\CT@rowb}%
{\ifnum0={\fi}\@gooble@rowcolor}%
}

\newcommand{\@gooble@rowcolor}[2][]{\@gooble@rowcolor@}
\newcommand{\@gooble@rowcolor@}[1][]{\@gooble@rowcolor@@}
\newcommand{\@gooble@rowcolor@@}[1][]{\ignorespaces}
\makeatother

\begin{document}
\begin{frame}{The MWE}%

\only<2>{\rowcolors{1}{blue!30}{blue!10}}
\only<1,3>{\rowcolors{1}{gray!30}{gray!10}}

\begin{center}
\begin{tabular}{cc}
A & B \\
A & B \\
A & B \\
\rowcolor<4>{green} A & B \\
\rowcolor<4,5>{yellow}A & B \\
\rowcolor<4-6>{green}A & B \\
\rowcolor<6>{red} A & B \\
A & B \\

\end{tabular}
\end{center}

\par
\visible<1>{Testing default row colouring ... \\}
\visible<2,3>{Testing change of default colors ...\\}
\visible<4-6>{Testing in-out of custom colors ...\\ (caution: The order of defaults colors can change)\\}

\vfill
\scriptsize{
Based of answer of Martin Scharrer
\url{http://tex.stackexchange.com/questions/18427/why-cant-i-wrap-rowcolor-in-only-beamer}}

\end{frame}

\end{document}

-
Thank you! I want to do the same thing for the cell color. \cellcolor<1>{red}, but it doesn't work. It seems I am not able to have the in-out effect of colors for cells. Please help! –  user16739 Aug 23 '12 at 14:32
I think I have solved the above issue by using \only command. Thanks again! –  user16739 Aug 23 '12 at 14:38

This is a simpler solution.

Just load the xcolor with the options table in the \documentclass. Because beamer loads by default xcolor package, therefore, it is necessary to pass the options in the \documentclass.

\documentclass[xcolor=table]{beamer} %-- pass the option table to xcolor package
\begin{document}
\begin{frame}
\frametitle{Famous Composers}
\begin{center}
\rowcolors{1}{}{lightgray} %-- this indicates the change in odd and pair rows
\begin{tabular}{|l|c|}\hline
J.\ S.\ Bach
& 1685--1750 \\
W.\ A.\ Mozart & 1756--1791 \\
L.\ Beethoven & 1770--1827 \\
F.\ Chopin
& 1810--1849 \\
R.\ Schumann
& 1810--1856 \\
B.\ Bartok & 1881--1945 \\ \hline
\end{tabular}
\end{center}
\end{frame}
\end{document}


Result:

sources:

Use xcolor for colored tables in a beamer slide

http://www.tug.org/pracjourn/2005-4/mertz/mertz.pdf

-
+1: A fairly good answer for being new user! I approve, that you also list your sources. Protip: If you also post an image of the output people will more likely upvote it. –  Henri Menke Dec 15 '13 at 0:33
Welcome to tex.se! I appreciate the effort you have put into your answer, however, I don't see yet how it addresses the OPs question. AFAIU, the question was about row-wise highlighting on subsequent slides using beamer overlays (e.g., slide 1: all rows are black, slide 2: row 1 is red, slide 3: row 2 is red, ...). –  Daniel Dec 16 '13 at 13:33
I understood he asked for changing color for row pairs and odds. In this case, that my answer is wrong, should I remove my answer? –  David Díaz Clavijo Dec 16 '13 at 19:58