Graphics, Figures & TablesFormatting rows of a table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
albart
Posts: 13
Joined: Mon Jul 06, 2009 12:54 pm

Formatting rows of a table

Post by albart »

Hello forum,

for a presentation, I would like to sequentially highligh rows of a table. Therefore, I simply use different copies of one table and then make the letters of the row which I want to emphasize red with function \textcolor{red}{what should be red}:

Code: Select all

Code, edit and compile here:
\documentclass{beamer}
\begin{document}
\begin{frame}
\begin{center}
\begin{tabular}{llll}
1 & 2 & 3 & 4\\
\hline
1&0.77&0.67&0.60\\
2&0.75 &0.67&0.65\\
\textcolor{red}{3}&\textcolor{red}{0.66} &\textcolor{red}{0.66}&\textcolor{red}{0.67}\\
\hline\\
\end{tabular}
\end{center}
\end{frame}
\begin{frame}
\begin{center}
\begin{tabular}{llll}
1 & 2 & 3 & 4\\
\hline
1&0.77&0.67&0.60\\
\textcolor{red}{3}&\textcolor{red}{0.66} &\textcolor{red}{0.66}&\textcolor{red}{0.67}\\
2&0.75 &0.67&0.65\\
\hline\\
\end{tabular}
\end{center}
\end{frame}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The problem is that I need to write \textcolor{red}{..} before each cell in the row. Is there a way to set the color or another format of the row with a simple macro? Putting the whole row in the macro did not work.

Thanks in advance,

Albart

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
renno
Posts: 54
Joined: Thu Jun 07, 2007 7:16 pm

Formatting rows of a table

Post by renno »

Hello there,

I suggest using the colortbl package. It offers commands such as \cellcolor and \rowcolor. I tried using \rowcolor, but could not overlay it using \only or \onslide commands from beamer. Maybe you can have a go with it. Below, you can have both rows highlighted at different slides with one frame only.

Code: Select all

Code, edit and compile here:
\documentclass{beamer}
\usepackage{colortbl}
\begin{document}
\begin{frame}
\begin{center}
\begin{tabular}{llll}
1 & 2 & 3 & 4\\
\hline
1&0.77&0.67&0.60\\
\only<2->{\cellcolor{blue!10}}2& \only<2->{\cellcolor{blue!10}}0.75 & \only<2->{\cellcolor{blue!10}}0.67& \only<2->{\cellcolor{blue!10}}0.65\\
\only<1->{\cellcolor{blue!10}}3& \only<1->{\cellcolor{blue!10}}0.66 & \only<1->{\cellcolor{blue!10}}0.66 & \only<1->{\cellcolor{blue!10}}0.67 \\
\hline\\
\end{tabular}
\end{center}
\end{frame}
\end{document}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Cheers,
If there is no way, we will make one...
Hanibal
albart
Posts: 13
Joined: Mon Jul 06, 2009 12:54 pm

Re: Formatting rows of a table

Post by albart »

Hello Renne,

thanks. I actually used the colortbl package but was not satisfied with the result. I would prefer to have the characters of the row which I want to emphasize in a different color and keep the background as it was.

Regards,

Albart
Post Reply