2

The following code in the MWE below makes the last (current) row shown on the respective slide overlayed in green:

  \begin{tabular}{cc}
    \cellcolor<+>{green}  A & B \\
    \cellcolor<+>{green}  C & D \\
    \cellcolor<+>{green}  E & F \\
    \cellcolor<+>{green}  D & E \\
    \cellcolor<+>{green}  F & G
  end{tabular}

This is great, but I need to add \cellcolor<+>{green} at the beginning of every line. Is there a way to define a new environment, say ovtab, which works exactly like tabular except that it does this automatically such that

  \begin{ovtab}{cc}
    A & B \\
    C & D \\
    E & F \\
    D & E \\
    F & G
  end{ovtab}

produces the same result?

Full MWE:

\documentclass[xcolor=table]{beamer}

\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



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

\newcommand{\@gooble@cellcolor}[2][]{\@gooble@cellcolor@}
\newcommand{\@gooble@cellcolor@}[1][]{\@gooble@cellcolor@@}
\newcommand{\@gooble@cellcolor@@}[1][]{\ignorespaces}
\makeatother
\begin{document}
\begin{frame}{Cell Coloring with In-out Effects}
   \begin{center}
   \begin{tabular}{cc}
  \cellcolor<+>{green}  A & B \\
  \cellcolor<+>{green}  C & D \\
  \cellcolor<+>{green}  E & F \\
  \cellcolor<+>{green}  D & E \\
  \cellcolor<+>{green}  F & G
    \end{tabular}
    \end{center}
    \end{frame}

\end{document}

1 Answer 1

2

Define a \newcolumntype{G}{>{\cellcolor<+>{green}\arraybackslash}c} and use \begin{tabular}{Gc}.

enter image description here

\documentclass[xcolor=table]{beamer}

\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

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

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

\usepackage{array} % needed <<<<<<<<<<
\newcolumntype{G}{>{\cellcolor<+>{green}\arraybackslash}c} % added <<<<<<<<<<

\begin{document}
%   \begin{frame}{Cell Coloring with In-out Effects}
%       \begin{center}
%           \begin{tabular}{cc}
%               \cellcolor<+>{green}  A & B \\
%               \cellcolor<+>{green}  C & D \\
%               \cellcolor<+>{green}  E & F \\
%               \cellcolor<+>{green}  D & E \\
%               \cellcolor<+>{green}  F & G
%           \end{tabular}
%       \end{center}
%   \end{frame}

\begin{frame}{Cell Coloring with In-out Effects Mk 2}
\begin{center}
    \begin{tabular}{Gc}% using  column type G <<<<<<<<<<<
        A & B \\
        C & D \\
        E & F \\
        D & E \\
        F & G
    \end{tabular}
\end{center}
\end{frame}

    
\end{document}

This will also work

\begin{tabular}{@{\cellcolor<+>{green}}cc} % 
        A & B \\
        C & D \\
        E & F \\
        D & E \\
        F & G
\end{tabular}

Update After follow up question.

Your code does not give the result you expected when applied to the right tabular of this structure,

c

generated by

\begin{frame}{Upside Down}
    \begin{tabular}{ll}
        \begin{tabular}{c}
        A \\B     
        \end{tabular}&  \begin{tabular}{c}
                            \begin{tabular}{Gl}
                                    C & D \\
                                    E & F \\
                                    G & H 
                            \end{tabular}
                        \end{tabular} \\
    \end{tabular} 
\end{frame} 

It will work fine using simpler syntax with minipages

\begin{frame}{Upside again}
    \begin{minipage}{2em}
        \begin{tabular}{c}
            A\\ B    
        \end{tabular} 
    \end{minipage}\quad
    \begin{minipage}{4em}
        \begin{tabular}{Gl}
            C & D \\
            E & F \\
            G & H 
        \end{tabular}
    \end{minipage}
\end{frame}

d

3
  • Thanks, it's working! There seems to be a some cases where my solution does not work, though. Try this: \begin{frame}{Upside Down} \begin{tabular}{ll} \begin{tabular}{c} A \\ B \end{tabular} & \begin{tabular}{c} \begin{tabular}[ht]{Gl} C & D \\ E & F \\ G & H \end{tabular} \end{tabular} \\ \end{tabular} \end{frame} For some reason, overlays are shown bottom up. Any idea how to fix this? Commented Mar 20, 2022 at 23:48
  • @Vitus Schäfftlein Please see the updated answer. Commented Mar 21, 2022 at 13:11
  • Great, that's what I needed. Thank you! Commented Mar 23, 2022 at 19:46

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .