如何在 beamer 中分段突出显示表格行?

如何在 beamer 中分段突出显示表格行?

我想知道如何在表格中突出显示行beamer,分段,这样当我呈现该部分时,我最初可以没有突出显示的行,然后是第一行,然后是第一行和第二行,等等。

我有下表,其中前两行突出显示:

\begin{frame}
\begin{table}
\begin{center}    
\begin{tabular}{lcc|ccc}
\multicolumn{6}{c}{Effect of Mandate on Fertility by Age: Employed Individuals} \\ \hline \hline
 & (1) & (2) & (3) & (4) & (5) \\
 & Has Child & Has Child LT 5 & Has Child LT 5 & Has Child LT 5 & Has Child LT 5 \\
VARIABLES & All & All & No HS Degree & HS or College & Masters or More \\ \hline
 &  &  &  &  &  \\
\rowcolor{LRed} Married Women 18-20*& -0.11 & -0.08* & -0.21*** & -0.00 & 0.00 \\
\rowcolor{LRed} After*Treatment State & [0.071] & [0.045] & [0.069] & [0.055] & [0.000]     \\
 &  &  &  &  &  \\
\rowcolor{LRed} Married Women 20-25*& -0.07*** & -0.07*** & -0.04 & -0.08*** & -0.38* \\
\rowcolor{LRed} After*Treatment State & [0.023] & [0.015] & [0.036] & [0.016] & [0.215] \\
 &  &  &  &  &  \\
Married Women 25-30*& -0.00 & 0.03** & 0.19*** & 0.01 & 0.11* \\
After*Treatment State & [0.019] & [0.012] & [0.032] & [0.014] & [0.058] \\
 &  &  &  &  &  \\
Married Women 30-35*& 0.01 & -0.01 & -0.09*** & -0.01 & 0.12** \\
After*Treatment State & [0.020] & [0.012] & [0.029] & [0.014] & [0.051] \\
 &  &  &  &  &  \\
Married Women 35-40*& -0.01 & -0.02** & -0.07*** & -0.03* & 0.10* \\
After*Treatment State & [0.019] & [0.012] & [0.026] & [0.014] & [0.053] \\
 &  &  &  &  &  \\
Observations & 152,366 & 152,366 & 34,081 & 110,324 & 7,961 \\
R-squared & 0.38 & 0.24 & 0.28 & 0.24 & 0.17 \\
 Mean of Dependant Variable & 0.48 & 0.09 & 0.07 & 0.10 & 0.08 \\ \hline \hline
\multicolumn{6}{c}{ Standard errors in brackets} \\
\multicolumn{6}{c}{ *** p$<$0.01, ** p$<$0.05, * p$<$0.1} \\
\end{tabular}
}
\end{center}
\end{table}
\end{frame}

答案1

评论中链接的解决方案是最合适的,但人们也可能使用该hf-tikz包(带有一点抽象,因为这不是该包的主要目的)。

一种可能的实现方式:

\documentclass{beamer}
\usepackage{lmodern}
\usepackage[beamer,customcolors]{hf-tikz}

\tikzset{hl/.style={
    set fill color=red!80!black!40,
    set border color=red!80!black,
  },
}

\begin{document}

\begin{frame}{Title}
\begin{center}
\resizebox{\textwidth}{!}{
\begin{tabular}{lcc|ccc}
\multicolumn{6}{c}{Effect of Mandate on Fertility by Age: Employed Individuals} \\ \hline \hline
 & (1) & (2) & (3) & (4) & (5) \\
 & Has Child & Has Child LT 5 & Has Child LT 5 & Has Child LT 5 & Has Child LT 5 \\
VARIABLES & All & All & No HS Degree & HS or College & Masters or More \\ \hline
 &  &  &  &  &  \\
\tikzmarkin<2->[hl]{a} Married Women 18-20*& -0.11 & -0.08* & -0.21*** & -0.00 & 0.00 \\
 After*Treatment State & [0.071] & [0.045] & [0.069] & [0.055] & [0.000] \tikzmarkend{a}    \\
 &  &  &  &  &  \\
\tikzmarkin<3->[hl]{b} Married Women 20-25*& -0.07*** & -0.07*** & -0.04 & -0.08*** & -0.38* \\
 After*Treatment State & [0.023] & [0.015] & [0.036] & [0.016] & [0.215] \tikzmarkend{b} \\
 &  &  &  &  &  \\
Married Women 25-30*& -0.00 & 0.03** & 0.19*** & 0.01 & 0.11* \\
After*Treatment State & [0.019] & [0.012] & [0.032] & [0.014] & [0.058] \\
 &  &  &  &  &  \\
Married Women 30-35*& 0.01 & -0.01 & -0.09*** & -0.01 & 0.12** \\
After*Treatment State & [0.020] & [0.012] & [0.029] & [0.014] & [0.051] \\
 &  &  &  &  &  \\
Married Women 35-40*& -0.01 & -0.02** & -0.07*** & -0.03* & 0.10* \\
After*Treatment State & [0.019] & [0.012] & [0.026] & [0.014] & [0.053] \\
 &  &  &  &  &  \\
Observations & 152,366 & 152,366 & 34,081 & 110,324 & 7,961 \\
R-squared & 0.38 & 0.24 & 0.28 & 0.24 & 0.17 \\
 Mean of Dependant Variable & 0.48 & 0.09 & 0.07 & 0.10 & 0.08 \\ \hline \hline
\multicolumn{6}{c}{ Standard errors in brackets} \\
\multicolumn{6}{c}{ *** p$<$0.01, ** p$<$0.05, * p$<$0.1} \\
\end{tabular}
}
\end{center}
\end{frame}

\end{document}

结果:

在此处输入图片描述

备注:\resizebox已采用,因为表格不适合框架。它来自graphicx,这是 Beamer 自动加载的一个包,因此无需明确加载它。

答案2

为了完成这个问题,我借用了弗朗因为这似乎是解决当前问题的一个相对简单的方法

\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

\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} A & B \\
    \rowcolor<4,5>{yellow}A & B \\
    \rowcolor<4-6>{green}A & B \\
    \rowcolor<6>{red} A & B \\
    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}

\end{document}

相关内容