使用 dcolumn 和覆盖的彩色单元格表格

使用 dcolumn 和覆盖的彩色单元格表格

我在这里发现了一个非常有用的问题,关于如何使用 dcolumn 在表中添加颜色带 dcolumn 的彩色文本,但我想使用叠加来做同样的事情,这样颜色只出现在第二张幻灯片上。有人知道如何做到这一点吗?非常感谢您的帮助。这是没有叠加的 MWE:

\documentclass[xcolor=table]{beamer}
\usepackage{amsmath}
\usepackage{array}
\usepackage{siunitx}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{caption}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\makeatletter
\def\DC@endright{$\hfil\egroup\@dcolcolor\box\z@\box\tw@\dcolreset}
\def\dcolcolor#1{\gdef\@dcolcolor{\color{#1}}}
\def\dcolreset{\dcolcolor{black}}
\dcolcolor{black}
\makeatother

\begin{document}
\begin{frame}
\caption{Cycle: seasonally adjusted regional unemployment rate}
\scriptsize
\setlength\tabcolsep{3pt}
\begin{tabular}{l  d{2.4}  d{2.6} d{2.6} d{2.6} d{2.5} d{2.6} d{2.4}}
\toprule
\toprule
            &\multicolumn{1}{c}{\text{(1)}}&\multicolumn{1}{c}    {\text{(2)}}&\multicolumn{1}{c}{\text{(3)}}&\multicolumn{1}{c}{\text{(4)}}&\multicolumn{1}{c}{\text{(5)}}&\multicolumn{1}{c}{\text{(6)}}&\multicolumn{1}{c}{\text{(7)}}\\
        &\multicolumn{1}{c}{\text{growth-rate}}&\multicolumn{1}{c}{\text{hire-rate}}&\multicolumn{1}{c}{\text{sep-rate}}&\multicolumn{1}{c}{\text{hire-e-rate}}&\multicolumn{1}{c}{\text{hire-n-rate}}&\multicolumn{1}{c}{\text{sep-e-rate}}&\multicolumn{1}{c}{\text{sep-n-rate}}\\
\midrule
\beta_{1}&      0.1122         &     -0.1687         &     -0.2809^{\ast}  &     -0.0567         &     -0.1120         &     -0.1765^{\ast\ast} &     -0.1044         \\
            &    (0.0554)         &    (0.0846)         &    (0.0867)         &    (0.0262)         &    (0.0666)         &    (0.0374)         &    (0.0590)         \\
[1em]
\beta_{2}&     -0.0148         &     -0.2478^{\ast\ast} &     -0.2330^{\ast}  &     \dcolor{red}-0.0848^{\ast}  &     -0.1630^{\ast\ast} &     -0.1271^{\ast}  &     -0.1058         \\
            &    (0.0394)         &    (0.0697)         &    (0.0909)         &    (0.0359)         &    (0.0408)         &    (0.0419)         &    (0.0531)         \\
\hline
\(R^{2}\)   &      0.066         &   \dcolcolor{red}   0.288         &       0.352         &       0.195         &       0.283         &       0.332         &       0.325         \\
Wald p & 0.0026 & 0.9198 & 0.0012 & 0.9766 &  0.9062 & 0.0007& 0.0137 \\
\bottomrule
\multicolumn{8}{l}{\scriptsize N = 136012, Standard errors in parentheses}\\
\multicolumn{8}{l}{\scriptsize ^{\ast} p<0.05, ^{\ast\ast} p<0.01, ^{\ast\ast\ast} p<0.001}\\
\end{tabular}
\end{frame}

我希望这样的事情能够奏效,但事实并非如此:

\documentclass[xcolor=table]{beamer}
\usepackage{amsmath}
\usepackage{array}
\usepackage{siunitx}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{caption}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\makeatletter
\def\DC@endright{$\hfil\egroup\@dcolcolor\box\z@\box\tw@\dcolreset}
\def\dcolcolor#1{\gdef\@dcolcolor{\color{#1}}}
\def\dcolreset{\dcolcolor{black}}
\dcolcolor{black}
\makeatother

\begin{frame}
\caption{Cycle: seasonally adjusted regional unemployment rate}
\scriptsize
\setlength\tabcolsep{3pt}
\begin{tabular}{l  d{2.4}  d{2.6} d{2.6} d{2.6} d{2.5} d{2.6} d{2.4}}
\toprule
\toprule
            &\multicolumn{1}{c}{\text{(1)}}&\multicolumn{1}{c}    {\text{(2)}}&\multicolumn{1}{c}{\text{(3)}}&\multicolumn{1}{c}{\text{(4)}}&\multicolumn{1}{c}{\text{(5)}}&\multicolumn{1}{c}{\text{(6)}}&\multicolumn{1}{c}{\text{(7)}}\\
        &\multicolumn{1}{c}{\text{growth-rate}}&\multicolumn{1}{c}{\text{hire-rate}}&\multicolumn{1}{c}{\text{sep-rate}}&\multicolumn{1}{c}{\text{hire-e-rate}}&\multicolumn{1}{c}{\text{hire-n-rate}}&\multicolumn{1}{c}{\text{sep-e-rate}}&\multicolumn{1}{c}{\text{sep-n-rate}}\\
\midrule
\beta_{1}&      \dcolor<2->{red}0.1122         &     -0.1687         &     -0.2809^{\ast}  &     -0.0567         &     -0.1120         &     -0.1765^{\ast\ast} &     -0.1044         \\
            &    (0.0554)         &    (0.0846)         &    (0.0867)         &    (0.0262)         &    (0.0666)         &    (0.0374)         &    (0.0590)         \\
[1em]
\beta_{2}&     -0.0148         &     -0.2478^{\ast\ast} &     -0.2330^{\ast}  &     -0.0848^{\ast}  &     -0.1630^{\ast\ast} &     -0.1271^{\ast}  &     -0.1058         \\
            &    (0.0394)         &    (0.0697)         &    (0.0909)         &    (0.0359)         &    (0.0408)         &    (0.0419)         &    (0.0531)         \\
\hline
\(R^{2}\)   &      0.066         &   \dcolcolor{red}   0.288         &       0.352         &       0.195         &       0.283         &       0.332         &       0.325         \\
Wald p & 0.0026 & 0.9198 & 0.0012 & 0.9766 &  0.9062 & 0.0007& 0.0137 \\
\bottomrule
\multicolumn{8}{l}{\scriptsize N = 136012, Standard errors in parentheses}\\
\multicolumn{8}{l}{\scriptsize ^{\ast} p<0.05, ^{\ast\ast} p<0.01, ^{\ast\ast\ast} p<0.001}\\
\end{tabular}
\end{frame}
\end{document}

答案1

表格中有几个不相关的错误(主要与缺少数学标记和标题使用不当有关)。一旦修复这些问题,如果您<2>\color命令中使用正常的 beamer 语法,颜色将只出现在第二层。

在此处输入图片描述

\documentclass[xcolor=table]{beamer}
\usepackage{amsmath}
\usepackage{array}
\usepackage{siunitx}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{caption}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\makeatletter
\def\DC@endright{$\hfil\egroup\@dcolcolor\box\z@\box\tw@\dcolreset}
\def\dcolcolor#1{\gdef\@dcolcolor{\color<2>{#1}}}
\def\dcolreset{\dcolcolor{black}}
\dcolcolor{black}
\makeatother

\begin{document}
\begin{frame}{Cycle: seasonally adjusted regional unemployment rate}
\scriptsize
\setlength\tabcolsep{3pt}
\begin{tabular}{>$l<$  d{2.4}  d{2.6} d{2.6} d{2.6} d{2.5} d{2.6} d{2.4}}
\toprule
            &\multicolumn{1}{c}{\text{(1)}}&\multicolumn{1}{c}    {\text{(2)}}&\multicolumn{1}{c}{\text{(3)}}&\multicolumn{1}{c}{\text{(4)}}&\multicolumn{1}{c}{\text{(5)}}&\multicolumn{1}{c}{\text{(6)}}&\multicolumn{1}{c}{\text{(7)}}\\
        &\multicolumn{1}{c}{\text{growth-rate}}&\multicolumn{1}{c}{\text{hire-rate}}&\multicolumn{1}{c}{\text{sep-rate}}&\multicolumn{1}{c}{\text{hire-e-rate}}&\multicolumn{1}{c}{\text{hire-n-rate}}&\multicolumn{1}{c}{\text{sep-e-rate}}&\multicolumn{1}{c}{\text{sep-n-rate}}\\
\midrule
\beta_{1}&      0.1122         &     -0.1687         &     -0.2809^{\ast}  &     -0.0567         &     -0.1120         &     -0.1765^{\ast\ast} &     -0.1044         \\
            &    (0.0554)         &    (0.0846)         &    (0.0867)         &    (0.0262)         &    (0.0666)         &    (0.0374)         &    (0.0590)         \\
[1em]
\beta_{2}&     -0.0148         &     -0.2478^{\ast\ast} &     -0.2330^{\ast}  &     \dcolcolor{red}-0.0848^{\ast}  &     -0.1630^{\ast\ast} &     -0.1271^{\ast}  &     -0.1058         \\
            &    (0.0394)         &    (0.0697)         &    (0.0909)         &    (0.0359)         &    (0.0408)         &    (0.0419)         &    (0.0531)         \\
\hline
R^{2}   &      0.066         &   \dcolcolor{red}   0.288         &       0.352         &       0.195         &       0.283         &       0.332         &       0.325         \\
\text{Wald p} & 0.0026 & 0.9198 & 0.0012 & 0.9766 &  0.9062 & 0.0007& 0.0137 \\
\bottomrule
\multicolumn{8}{l}{\scriptsize $N = 136012$, Standard errors in parentheses}\\
\multicolumn{8}{l}{\scriptsize $^{\ast} p<0.05$, $^{\ast\ast} p<0.01$, $^{\ast\ast\ast} p<0.001$}\\
\end{tabular}
\end{frame}

\end{document}

相关内容