[Tex/LaTex] Highlight each column of a table

beamer

I created a simple table using a latex table generator. I want to highlight each of the columns in the table.

I want to add this table to the slides, I'm using the beamer documentclass this is my first time.

In the table I want to highlight in the 1st slide column x1.

2nd slide, column x2(without x1 highlighted)

3d slide column x3 (without x1 and x2 highlighted)

4th slide column x1 and x2

and so on.

Here is the script that I have which gives an error:

\documentclass{beamer}
\usepackage{basileabeam}
\usepackage{lmodern}
\usepackage{xcolor}

\begin{document}

\begin{frame}{Title}
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l|
>{\columncolor[HTML]{FFCE93}}l |l|l|}
\hline
y & {\color[HTML]{333333} $x_1$} & $x_2$ & $x_3$ \\ \hline
5 & {\color[HTML]{333333} 3.3} & 2.1 & 4.1 \\ \hline
1.1 & {\color[HTML]{333333} 2.2} & 3.2 & 2.1 \\ \hline
2 & {\color[HTML]{333333} 5.1} & 8.1 & 2.2 \\ \hline
4 & {\color[HTML]{333333} 2.6} & 7 & 1 \\ \hline
\end{tabular}
\end{table}
\end{frame}

\end{document}

Here are the errors:

! Undefined control sequence.

! LaTeX Error: Illegal character in array arg.

Best Answer

Try :

\documentclass[table]{beamer} % <---
%\usepackage{basileabeam}     % <--- i don't have this package
\usepackage{lmodern}

\begin{document}

\begin{frame}{Title}
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l| >{\columncolor[HTML]{FFCE93}\color{blue}}l |
            l|l|}
\hline
y   & $x_1$ & $x_2$ & $x_3$ \\ \hline
5   & 3.3   & 2.1   & 4.1   \\ \hline
1.1 & 2.2   & 3.2   & 2.1   \\ \hline
2   & 5.1   & 8.1   & 2.2   \\ \hline
4   & 2.6   & 7     & 1     \\ \hline
\end{tabular}
\end{table}
\end{frame}

\end{document}

enter image description here

  • For coloring table columns/rows instead of usepackage{xcolor} you had to load \usepackage[table]{xcolor}.
  • beamer already load xcolor package, so you need only ad option table to beamer document class options (as is done in MWE above).