在某些幻灯片上,我想使用彩色背景突出显示一些文本,如下所示:
在此示例中,我夸大了文本周围边框的宽度来表明我想要的效果。
我手动制作了这个示例。我想要一个宏,\highlighton
这样我就可以通过编写来产生效果\highlighton<1>{`to protrude out'}
。这个奇妙的包tcolorbox
提供了几乎可以解决问题的宏。这是一个例子。
\documentclass{beamer}
\usepackage{etex}
\setbeamertemplate{navigation symbols}{}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage{times}
\def\highlighton<#1>#2{%
\alt<#1>{\tcbox[enhanced,boxrule=0pt,colback=red!50,interior style=
{opacity=0.7},frame style={opacity=0.5},nobeforeafter,tcbox raise base,shrink
tight,extrude by=5mm]{#2}}{#2}%
}
\begin{document}
\begin{frame}
\textbf{Extrude}, \textit{v}.\ trans. \textbf{1}.\ To thrust (a person) out or forth;
to urge or force out; to expel. \textbf{a}.\ with obj.\ a person. \textbf{b}.\ with
obj.\ a material thing; in mod.\ use esp.\ to exclude (an embryo, ova, etc.). Also
occas.\ with sense \highlighton<1>{`to protrude out'}. \textbf{c}. with an immaterial
thing as obj. \textbf{d}.\ To shape (metals, plastics, etc.)\ by forcing them through
dies. \textbf{2}.\ intr.\ for refl. To protrude out. rare.
\pause
\end{frame}
\end{document}
此代码(其中extrude by 5mm
生成边框)产生以下输出。文本前突出显示的文本“变暗”,但文本后突出显示的文本不是。有没有办法产生我想要的效果?
答案1
我的答案与 Claudio Fiandrino 的想法相同。但它使用tcolorbox
(v2.61),您可以在页面上使用任意数量的突出显示。
\documentclass{beamer}
\usepackage{etex}
\setbeamertemplate{navigation symbols}{}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage{times}
\def\remember#1#2{%
\tcbox[enhanced,remember as={#1},frame hidden,interior hidden,boxrule=0pt,nobeforeafter,
tcbox raise base,shrink tight]{#2}%
\pgfkeyssetvalue{/myremember/#1}{#2}%
}
\def\highlighton<#1>#2{%
\alt<#1>{\tikz[overlay,remember picture]\node at (#2){%
\tcbox[enhanced,boxrule=0pt,colback=red!50,interior style={opacity=0.7},
frame style={opacity=0.5},nobeforeafter,tcbox raise base,shrink tight,
extrude by=5mm]{\pgfkeysvalueof{/myremember/#2}}};}{}%
}
\begin{document}
\begin{frame}
\textbf{Extrude}, \textit{v}.\ trans. \textbf{1}.\ To thrust (a person) out or forth;
to urge or force out; to expel. \textbf{a}.\ with obj.\ a person. \textbf{b}.\ with
obj.\ a material thing; in mod.\ use esp.\ to exclude (an embryo, ova, etc.). Also
occas.\ with sense \remember{protrude}{`to protrude out'}. \textbf{c}. with an immaterial
thing as obj. \textbf{d}.\ To shape \remember{etc}{(metals, plastics, etc.)}\ by forcing them through
dies. \textbf{2}.\ intr.\ for refl. To protrude out. rare.%
\highlighton<2>{protrude}
\highlighton<3>{etc}
\pause
\end{frame}
\end{document}
答案2
比我原先想象的要困难得多。问题在于,如果执行操作之内文本的不透明度在框中不是均匀保留的。因此需要以某种方式标记要突出显示的文本并执行之后实际的突出显示。
这是仅适用于 TikZ 的一个可能解决方案:
\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
\usepackage{times}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}
\newcounter{storetxt}
\newcounter{showtxt}
\makeatletter
\newcommand{\tikzmark}[2]{
\tikz[remember picture,baseline=-0.5ex]
\node[inner sep=0pt,outer sep=0pt] (#1) {#2};%
\stepcounter{storetxt}
\global\@namedef{text@\thestoretxt\expandafter}\expandafter{#2}% storing text
}
\newcommand<>{\highlighton}[1]{
\stepcounter{showtxt}
\tikz[overlay,remember picture]{
\edef\txt{\@nameuse{text@\theshowtxt}}% retrieve the correct text
\node[opacity=0.8,text opacity=1,rounded corners,
minimum width=3cm,minimum height=1.5cm,% size of the box
background fill=red!50,fill on=#2,% box visibility
visible on=#2% we need this to have the filling only in some overlays,
% otherwise the opacity would affect all overlays
]at(#1){\txt};
}
}
\makeatother
\begin{document}
\begin{frame}
\textbf{Extrude}, \textit{v}.\ trans. \textbf{1}.\ To thrust (a person) out or forth;
to urge or force out; to expel. \textbf{a}.\ with obj.\ a person. \textbf{b}.\ with
obj.\ a material thing; in mod.\ use esp.\ to exclude (an embryo, ova, etc.). Also
occas.\ with sense \tikzmark{mark}{`to protrude out'}. \textbf{c}. with an immaterial
thing as obj. \textbf{d}.\ To shape \tikzmark{m2}{(metals, plastics, etc.)}\ by forcing them through
dies. \textbf{2}.\ intr.\ for refl. To protrude out. rare.
\highlighton<2>{mark}% important to have it here after the text
\highlighton<3>{m2}
\end{frame}
\end{document}
结果:
答案3
使用这个包可以达到类似的效果spot
:
\documentclass{beamer}
\usepackage{spot}
\begin{document}
\begin{frame}
\textbf{Extrude}, \textit{v}.\ trans. \textbf{1}.\ To thrust (a person) out or forth;
to urge or force out; to expel. \textbf{a}.\ with obj.\ a person. \textbf{b}.\ with
obj.\ a material thing; in mod.\ use esp.\ to exclude (an embryo, ova, etc.). Also
occas.\ with sense \spot<1>(foo){`to protrude out'}. \textbf{c}. with an immaterial
thing as obj. \textbf{d}.\ To shape (metals, plastics, etc.)\ by forcing them through
dies. \textbf{2}.\ intr.\ for refl. To protrude out. rare.
\end{frame}
\end{document}