我有一个“有效”的方法,但我想知道是否有更优雅的解决方案。我想在 beamer 中的 itemize 后面框出一些文本,所以我正在这样做:
\documentclass{beamer}
\begin{document}
\begin{frame}
\begin{itemize}[<+->]
\item Software-as-a-Service?
\item Platform-as-a-Service?
\item \only<-4>{Infrastructure-as-a-Service}\only<5->{\fcolorbox{red}{white}{Infrastructure-as-a-Service}}?
\item Other-stuff-as-a-Service?
\end{itemize}
\end{frame}
\end{document}
我得到了我想要的效果(在盒装幻灯片上增加了一些空间,这并不理想),但我想知道是否有更自然的方法来做到这一点?我尝试在网上和可信赖的网站上搜索texdoc beamer
,但也许我找错了地方。
我也尝试过:
\item \fcolorbox<beamer:6>{red}{white}{Infrastructure-as-a-Service}?
但那只剩下一个黑框,直到红色框被突出显示
答案1
你可以使用经过验证的tikzmark
想法
代码
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
% tikzmark command, for shading over items
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\begin{document}
\begin{frame}
\begin{itemize}[<+->]
\item Software-as-a-Service?
\item Platform-as-a-Service?
\item \tikzmark{infrastructure}{Infrastructure-as-a-Service}
\item Other-stuff-as-a-Service?
\end{itemize}
\pause\tikz[overlay,remember picture]{\draw[draw=red,thick,double,fill opacity=0.2] ($(infrastructure)+(-0.5,0.4)$) rectangle ($(infrastructure)+(6,-0.2)$);}
\end{frame}
\end{document}
答案2
另一种方法是利用使用 TikZ 节点在 Beamer 中突出显示。
代码:
\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{xparse}
\tikzset{
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}
},
}
\tikzset{
background fill/.style={fill=#1},
background fill/.default={white},
fill on/.style={alt=#1{}{background fill}},
}
\tikzset{
background draw/.style={draw=#1},
background draw/.default={white},
draw on/.style={alt=#1{}{background draw}},
}
\tikzset{
background filldraw/.style args={#1 filled by #2}{draw=#1, fill=#2},
background filldraw/.default=white filled by white,
filldraw on/.style={alt=#1{}{background filldraw}},
}
\tikzset{highlighting/.style={
append after command={
\pgfextra{
\path[rounded corners,
background draw=red,
draw on=<#1>,
overlay] ($(\tikzlastnode.south west)+(-0.015,-0.1)$) % to have some offset
rectangle ($(\tikzlastnode.north east)+(0.015,0.065)$);
}
}
}
}
\NewDocumentCommand{\highlight}{r<> m}{%
\tikz[baseline=(A.base)]
\node[highlighting=#1,
inner sep=0pt] (A) {#2};%
}
\begin{document}
\begin{frame}{Itemize with styles}
\begin{itemize}[<+->]
\item Software-as-a-Service?
\item Platform-as-a-Service?
\item \highlight<5>{Infrastructure-as-a-Service}?
\item Other-stuff-as-a-Service?
\end{itemize}
\end{frame}
\end{document}
结果:
代码注释
由于选项 ,创建的 TikZ 节点不会占用太多空间inner sep=0pt
,但由于其尺寸在文本周围非常紧密,因此创建的突出显示框会在周围添加一些空间(通过库创建的偏移量calc
)。为了避免这个额外的空间可能破坏对齐,overlay
已将选项引入到突出显示路径中。
现在,无需改变 中的任何内容document
,就可以通过选择不同的样式来获得不同的效果:
\tikzset{highlighting/.style={
append after command={
\pgfextra{
\path[rounded corners,
background fill=red!30, % filling
fill on=<#1>, % filling overlay specification
overlay] ($(\tikzlastnode.south west)+(-0.015,-0.1)$) % to have some offset
rectangle ($(\tikzlastnode.north east)+(0.015,0.065)$);
}
}
}
}
给出:
尽管:
\tikzset{highlighting/.style={
append after command={
\pgfextra{
\path[rounded corners,
background filldraw=red filled by red!30, % border+filling
filldraw on=<#1>, % overlay specification
overlay] ($(\tikzlastnode.south west)+(-0.015,-0.1)$) % to have some offset
rectangle ($(\tikzlastnode.north east)+(0.015,0.065)$);
}
}
}
}
给出:
可定制偏移
使用此改进版本,可以hf-tikz
通过偏移量自定义突出显示区域(从包中借用的想法)。此偏移量最终是 pgfkeys,其值必须在命令的可选参数中声明\highlight
:
\highlight<overlay specification>[offsets]{text}
如果没有[offsets]
指定,则采用初始值。
代码:
\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{xparse}
\tikzset{
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}
},
}
\tikzset{
background fill/.style={fill=#1},
background fill/.default={white},
fill on/.style={alt=#1{}{background fill}},
}
\tikzset{
background draw/.style={draw=#1},
background draw/.default={white},
draw on/.style={alt=#1{}{background draw}},
}
\tikzset{
background filldraw/.style args={#1 filled by #2}{draw=#1, fill=#2},
background filldraw/.default=white filled by white,
filldraw on/.style={alt=#1{}{background filldraw}},
}
\pgfkeys{/highlight/.cd,
above right offset/.initial={0.015,0.065},
above right offset/.get=\aboverightoffset,
above right offset/.store in=\aboverightoffset,
below left offset/.initial={-0.015,-0.1},
below left offset/.get=\belowleftoffset,
below left offset/.store in=\belowleftoffset,
}
\tikzset{highlighting/.style={
append after command={
\pgfextra{
\path[rounded corners,
background filldraw=red filled by red!30,% border+filling
filldraw on=<#1>, % overlay specification
overlay] ($(\tikzlastnode.south west)+(\belowleftoffset)$) % to have some offset
rectangle ($(\tikzlastnode.north east)+(\aboverightoffset)$);
}
}
}
}
\NewDocumentCommand{\highlight}{r<> O{} m}{%
\pgfkeys{/highlight/.cd,#2}
\tikz[baseline=(A.base)]
\node[highlighting=#1,
inner sep=0pt] (A) {#3};%
}
\begin{document}
\begin{frame}{Itemize with styles}
\begin{itemize}[<+->]
\item Software-as-a-Service?
\item Platform-as-a-Service?
\item \highlight<5>{Infrastructure-as-a-Service}?
\item \highlight<6>[below left offset={-0.1,-0.2},above right offset={0.25,0.15}]{Other-stuff-as-a-Service}?
\end{itemize}
\end{frame}
\end{document}
结果: