我只想让幻灯片 2 中的行颜色发生变化,如何使用 tabularray 来实现,我试过使用\only<4>{row{2} = {blue!30},}
,但没有效果
我也用过\alt<1>{\SetRow{background}{blue!30}}{}
\documentclass{beamer}
\usepackage{tikz}
\usepackage{tabularray}
\usetikzlibrary{tikzmark}
\tikzset{
every picture/.style={remember picture,baseline},
every node/.style={
inner sep=0pt,
anchor=base,
minimum width=1.8cm,
align=center,
text depth=.25ex,
outer sep=1.5pt},
every path/.style={
thick,
rounded corners
}
}
\begin{document}
\begin{frame}
\begin{tblr}{
colspec = {|m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.25\textwidth}|
},
\only<4>{row{2} = {Gold!30},}
}
\hline \hline
x & y &z & e & d & f\\ \hline \hline
x & y &z & e & d & f\\ \hline \hline
x & y &z & e & d & f\\ \hline \hline
x & y &z & e & d & f\\ \hline \hline
x & y &z & e & d & f\tikzmark{a}\\ \hline \hline
\end{tblr}
\pause
\begin{tikzpicture}[remember picture,overlay]
\node [right=2cm,above=2cm,minimum width=0pt] at (pic cs:a) (A) {A};
\draw [<-,out=5,in=180] ([xshift=15pt]{pic cs:a}) to (A);
\end{tikzpicture}
\end{frame}
\end{document}
答案1
您可以使用库functional
并创建一个可以在内部使用的命令tblr
环境中使用该命令来设置行颜色(请参阅当前tabularray
手动的:
\documentclass{beamer}
\usepackage{tabularray}
\UseTblrLibrary{functional}
\prgNewFunction\styleRowOnly{mmm}{
\only<#1>{\rowSetStyle{#2}{#3}}
}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{
every picture/.style={
remember picture,
baseline
},
every node/.style={
inner sep=0pt,
anchor=base,
minimum width=1.8cm,
align=center,
text depth=.25ex,
outer sep=1.5pt},
every path/.style={
thick,
rounded corners
}
}
\begin{document}
\begin{frame}
\begin{tblr}{
colspec = {|m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.25\textwidth}|
},
process=\styleRowOnly{4}{2}{blue!30},
}
\hline \hline
x & y & z & e & d & f \\ \hline \hline
x & y & z & e & d & f \\ \hline \hline
x & y & z & e & d & f \\ \hline \hline
x & y & z & e & d & f \\ \hline \hline
x & y & z & e & d & f\tikzmark{a} \\ \hline \hline
\end{tblr}
\pause
\begin{tikzpicture}[remember picture, overlay]
\node[right=2cm, above=2cm, minimum width=0pt] at (pic cs:a) (A) {A};
\draw[<-, out=5, in=180] ([xshift=15pt]{pic cs:a}) to (A);
\end{tikzpicture}
\end{frame}
\end{document}
另一个可能更简单的解决方案是对第二行使用自定义颜色,只需在相关框架上进行更改即可:
\documentclass{beamer}
\usepackage{tabularray}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{
every picture/.style={
remember picture,
baseline
},
every node/.style={
inner sep=0pt,
anchor=base,
minimum width=1.8cm,
align=center,
text depth=.25ex,
outer sep=1.5pt},
every path/.style={
thick,
rounded corners
}
}
\begin{document}
\colorlet{rowiicolor}{transparent!0}
\begin{frame}
\only<4>{\colorlet{rowiicolor}{blue!30}}
\begin{tblr}{
colspec = {|m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.25\textwidth}|
},
row{2} = {rowiicolor},
}
\hline \hline
x & y & z & e & d & f \\ \hline \hline
x & y & z & e & d & f \\ \hline \hline
x & y & z & e & d & f \\ \hline \hline
x & y & z & e & d & f \\ \hline \hline
x & y & z & e & d & f\tikzmark{a} \\ \hline \hline
\end{tblr}
\pause
\begin{tikzpicture}[remember picture, overlay]
\node[right=2cm, above=2cm, minimum width=0pt] at (pic cs:a) (A) {A};
\draw[<-, out=5, in=180] ([xshift=15pt]{pic cs:a}) to (A);
\end{tikzpicture}
\end{frame}
\end{document}
输出与上面相同。
如果您想为不同幻灯片上的不同列和行着色,您可以执行以下操作:
\documentclass{beamer}
\usepackage{tabularray}
\UseTblrLibrary{functional}
\prgNewFunction\styleRowOnly{mmm}{
\only<#1>{\rowSetStyle{#2}{#3}}
}
\prgNewFunction\styleColOnly{mmm}{
\only<#1>{\columnSetStyle{#2}{#3}}
}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{
every picture/.style={
remember picture,
baseline
},
every node/.style={
inner sep=0pt,
anchor=base,
minimum width=1.8cm,
align=center,
text depth=.25ex,
outer sep=1.5pt},
every path/.style={
thick,
rounded corners
}
}
\begin{document}
\begin{frame}
\begin{tblr}{
colspec = {|m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.1\textwidth}|
m{0.25\textwidth}|
},
process={
\styleRowOnly{2}{2}{green!30}
\styleRowOnly{3}{5}{blue!30}
\styleColOnly{4}{4}{red!30}
},
}
\hline \hline
x & y & z & e & d & f \\ \hline \hline
x & y & z & e & d & f \\ \hline \hline
x & y & z & e & d & f \\ \hline \hline
x & y & z & e & d & f \\ \hline \hline
x & y & z & e & d & f\tikzmark{a} \\ \hline \hline
\end{tblr}
\pause
\begin{tikzpicture}[remember picture, overlay]
\node[right=2cm, above=2cm, minimum width=0pt] at (pic cs:a) (A) {A};
\draw[<-, out=5, in=180] ([xshift=15pt]{pic cs:a}) to (A);
\end{tikzpicture}
\end{frame}
\end{document}
更简单的方法在这里失败了,因为您总是会覆盖一个单元格的颜色,从而transparent!0
留下难看的间隙。