投影机中的细胞覆盖

投影机中的细胞覆盖

我使用了此处发布的代码线突出显示表格中的单元格:

\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



\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}{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} C & D \\
    \rowcolor<4,5>{yellow} E & F \\
    \rowcolor<4-6>{green} G & H \\
    \rowcolor<6>{red} Y & S \\
    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{https://tex.stackexchange.com/questions/18427/why-cant-i-wrap-rowcolor-in-only-beamer}}

\end{frame} 

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

    \end{tabular}
    \end{center}
    \end{frame}

\end{document}

但如果我把最后一帧改成

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

\end{tabular}
\end{center}
\end{frame}

然后整个第二行都会突出显示。有人能告诉我如何重新定义上面的 \cellcolor 以确保只有一个单元格会突出显示吗?

答案1

简单的重新定义可以实现\cellcolor覆盖感知:

\documentclass[xcolor=table]{beamer}
\renewcommand<>\cellcolor[1]{\only#2{\beameroriginal\cellcolor{#1}}}

\begin{document}

\begin{frame}

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

\end{frame}

\end{document}

在此处输入图片描述

相关内容