投影儀表格中具有輸入輸出效果的單元格著色(突出顯示)

投影儀表格中具有輸入輸出效果的單元格著色(突出顯示)

我需要在表格的單元格中進行單元格著色(或突出顯示效果)beamer點擊後(我的意思是,我計劃在該框架中討論一些內容,並且我將在演講結束時強調單元格中的一個數字),並且我嘗試了許多命令,例如\onslide<>\only<>\visible<>和新命令\colorbox,但是他們中的任何一個都起作用了。最後,我遇到了一些\rowcolor<>{colorname}程式碼,我嘗試安排這些程式碼(完全不知道 newcommand 結構)用於具有輸入輸出效果的單元格著色,但是出現了問題,所以我收到了這樣的錯誤

放錯地方了\noalign

它有什麼問題呢?

\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{\noalign{\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}

答案1

\noalign從 的定義中刪除該指令\cellcolor

\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{http://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}

在此輸入影像描述

相關內容