在表格投影仪中自动进行行颜色叠加

在表格投影仪中自动进行行颜色叠加

以下 MWE 中的以下代码使相应幻灯片上显示的最后一行(当前行)以绿色覆盖:

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

这很好,但我需要\cellcolor<+>{green}在每一行开头添加。有没有办法定义一个新环境,比如ovtab,它的工作原理与 完全相同tabular,只是它会自动执行此操作,以便

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

产生相同的结果?

完整 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

定义 a\newcolumntype{G}{>{\cellcolor<+>{green}\arraybackslash}c} 并使用 \begin{tabular}{Gc}

在此处输入图片描述

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

这也行得通

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

更新之后进行后续问题。

当将代码应用到此结构的正确表格时,它不会给出您预期的结果,

C

生成于

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

使用更简单的minipage语法

\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

相关内容