看起来\rowscolors
(of xcolor
) 和\tikzmarkin
(of hf-tikz
) 不兼容。下面是一个说明该问题的简单示例:
\documentclass[xcolor={table,dvipsnames}]{beamer}
\usepackage[customcolors,beamer]{hf-tikz}
\usetheme{Copenhagen}
\begin{document}
\begin{frame}{}
\begin{table}
\centering
\rowcolors{2}{gray!20}{white}
\begin{tabular}{lccc}
A & B & C & D \\
00 & 100\% & 100\% & 0\% \\
\tikzmarkin<1>{a} 05 & 58 & 181 & 50 \tikzmarkend{a} \\
\tikzmarkin<2>{b} 10 & 87 & 112 & 1.6 \tikzmarkend{b} \\
20 & 92 & 115 & 1.6 \\
30 & 87 & 117 & 1.6 \\
40 & 81 & 121 & 1.6 \\
\end{tabular}
\end{table}%
\end{frame}
\end{document}
请注意,创建的注释hf-tikz
仅显示在行的第一个单元格上方,而它应该覆盖整行。下图显示了上述示例的输出:
此外,似乎行的第一个单元格不再像应该的那样左对齐。有什么提示可以解决这个问题吗?
答案1
作为一种解决方法,不要使用hf-tikz
,而是自己进行突出显示:
\documentclass[xcolor={table,dvipsnames}]{beamer}
\usetheme{Copenhagen}
% from https://tex.stackexchange.com/a/315248/36296
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,fit,tikzmark}
% Some options common to all the nodes and paths
\tikzset{
every picture/.style={remember picture,baseline},
every node/.style={anchor=base,align=center,outer sep=1.5pt},
every path/.style={thick},
}
\newcommand\marktopleft[1]{%
\tikz[overlay,remember picture]
\node (marker-#1-a) at (.1em,.3em) {};%
}
\newcommand\markbottomright[1]{%
\tikz[overlay,remember picture]
\node (marker-#1-b) at (.1em,.3em) {};%
\tikz[overlay,remember picture,inner sep=1pt]
\node[draw=red,rounded corners,fit=(marker-#1-a.north west) (marker-#1-b.south east)] {};%
}
\begin{document}
\begin{frame}{}
\begin{table}
\centering
\rowcolors{2}{gray!20}{white}
\begin{tabular}{lccc}
A & B & C & D \\
00 & 100\% & 100\% & 0\% \\
\only<1>{\marktopleft{a}}05 & 58 & 181 & 50\only<1>{\markbottomright{a}}\\
\only<2>{\marktopleft{b}}10 & 87 & 112 & 1.6\only<2>{\markbottomright{b}}\\
20 & 92 & 115 & 1.6 \\
30 & 87 & 117 & 1.6 \\
40 & 81 & 121 & 1.6 \\
\end{tabular}
\end{table}%
\end{frame}
\end{document}