比如当我从一行过渡到下一行时,我希望行颜色发生变化,从而产生悬停效果。每次只会为选定的行着色。
另外,如何将表格定位在幻灯片上的特定坐标点?
\documentclass{beamer}
\usepackage{color, colortbl}
\definecolor{background}{rgb}{0.84,0.92,0.95}
\begin{document}
\begin{frame}
\setbeamercovered{dynamic}
\begin{tabular}{|c|c|c|c|}
\hline
J & K & $Q_{n}$ & $\overline{Q_{n}}$ \\
\hline
\onslide<1> {\rowcolor{background}}
\onslide<1->{0} & \onslide<1->{0} & \onslide<1->{0} & \onslide<1->{0} \\
\hline
\onslide<2> {\rowcolor{background}}
\onslide<2->{0} & \onslide<2->{1} & \onslide<2->{0} & \onslide<2->{0} \\
\hline
\onslide<3> {\rowcolor{background}}
\onslide<3->{1} & \onslide<3->{0} & \onslide<3->{0} & \onslide<3->{0} \\
\hline
\onslide<4> {\rowcolor{background}}
\onslide<4->{1} & \onslide<4->{1} & \onslide<4->{0} & \onslide<4->{0} \\
\hline
\end{tabular}
\end{frame}
\end{document}
答案1
\documentclass[xcolor=table]{beamer}
\definecolor{background}{rgb}{0.84,0.92,0.95}
\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}
\setbeamercovered{dynamic}
\begin{tabular}{|c|c|c|c|}
\hline
J & K & $Q_{n}$ & $\overline{Q_{n}}$ \\
\hline
\rowcolor<1>{background} \onslide<1->{0} & \onslide<1->{0} & \onslide<1->{0} & \onslide<1->{0} \\
\hline
\rowcolor<2>{background}
\onslide<2->{0} & \onslide<2->{1} & \onslide<2->{0} & \onslide<2->{0} \\
\hline
\rowcolor<3>{background}
\onslide<3->{1} & \onslide<3->{0} & \onslide<3->{0} & \onslide<3->{0} \\
\hline
\rowcolor<4>{background}
\onslide<4->{1} & \onslide<4->{1} & \onslide<4->{0} & \onslide<4->{0} \\
\hline
\end{tabular}
\end{frame}
\end{document}
答案2
供参考,如果 而不是{tabular}
,您使用{NiceTabular}
(nicematrix
带有键color-inside
) 及其内置命令(而不是提供的\rowcolor
命令),您将直接获得预期的输出(但您需要多次编译)。\rowcolor
colortbl
\documentclass{beamer}
\usepackage{nicematrix}
\definecolor{background}{rgb}{0.84,0.92,0.95}
\begin{document}
\begin{frame}
\setbeamercovered{dynamic}
\begin{NiceTabular}{|c|c|c|c|}[color-inside]
\hline
J & K & $Q_{n}$ & $\overline{Q_{n}}$ \\
\hline
\onslide<1> {\rowcolor{background}}
\onslide<1->{0} & \onslide<1->{0} & \onslide<1->{0} & \onslide<1->{0} \\
\hline
\onslide<2> {\rowcolor{background}}
\onslide<2->{0} & \onslide<2->{1} & \onslide<2->{0} & \onslide<2->{0} \\
\hline
\onslide<3> {\rowcolor{background}}
\onslide<3->{1} & \onslide<3->{0} & \onslide<3->{0} & \onslide<3->{0} \\
\hline
\onslide<4> {\rowcolor{background}}
\onslide<4->{1} & \onslide<4->{1} & \onslide<4->{0} & \onslide<4->{0} \\
\hline
\end{NiceTabular}
\end{frame}
\end{document}