
\documentclass[xcolor=table ]{beamer}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\title[Your Short Title]{Your Presentation}
\author{You}
\institute{Where You're From}
\date{Date of Presentation}
\begin{document}
\begin{frame}{Introduction}
\begin{itemize}
\item <1-> Your introduction goes here!
\item <2> Use \texttt{itemize} to organize your main points.
\end{itemize}
\end{frame}
\begin{frame}
\begin{itemize}
\item Your introduction goes here!
\item {\colorbox{yellow} {Use \texttt{itemize} to organize your main points.}}
\end{itemize}
\end{frame}
\end{document}
此 MWE 顯示了逐項清單。顯示兩個連續項目後,我希望突出顯示第二個項目第三步。我透過複製框架實現了這一點。這可以透過疊加來實現,而不需要手動複製幀嗎
答案1
簡單的解決方案是使用\only
使\colorbox{yellow}
程式碼部分成為條件:
\begin{frame}{Introduction}
\begin{itemize}
\item <1-> Your introduction goes here!
\item <2-> \only<3>{\colorbox{yellow}}{Use \texttt{itemize} to organize your main points.}
\end{itemize}
\end{frame}
然而,這有一個問題:因為\colorbox
填充了文字周圍的某些區域,所以它改變了間距,從而導致可見的跳躍(嘗試看看)。
人們可以透過始終使用 a 來解決此問題\colorbox
,但在不應突出顯示時用背景顏色填充它。由於這有點混亂,我將為此目的定義一個新命令:
\documentclass[xcolor=table]{beamer}
\usepackage[english]{babel}
\title[Your Short Title]{Your Presentation}
\author{You}
\institute{Where You're From}
\date{Date of Presentation}
\newcommand<>{\mycolorbox}[3][white]{{%
% #1 = default color when overlay specification is not fulfilled (default: white)
% #2 = color when overlay specification is fulfilled
% #3 = text to be displayed
% #4 = the actual overlay specification
\def\mycolor{#1}%
\only#4{\def\mycolor{#2}}%
\colorbox{\mycolor}{#3}%
}}
\begin{document}
\begin{frame}{Introduction}
\begin{itemize}
\item <1-> Your introduction goes here!
\item <2-> \mycolorbox<3>{yellow}{Use \texttt{itemize} to organize your main points.}
\end{itemize}
\end{frame}
\end{document}
的語法在的使用者指南 部分\newcommand<>
中進行了解釋beamer
9.6.1 使命令和環境覆蓋規範感知。第一個參數是要定義的巨集的名稱(\mycolorbox
在本例中),然後是不包含覆蓋規範的參數數量,最後是第一個參數的預設值。在命令內部,可以使用#
字元後面接其編號(#1
等#2
,請參閱註釋)來引用參數。
雙大括號{{
和}}
的存在是為了創建 TeX 組,這意味著任何巨集(重新)定義最終都會被忘記。外部對界定命令的內容,而內部對是 TeX 群組。
然後我使用\def
(我也可以使用\newcommand
)來定義一個新的宏,\mycolor
它最初是預設顏色。然後,我使用\only
,有條件地將其重新定義為所需的顏色(本例中為黃色)。最後,我調用\colorbox
命令。
順便說一句,也可以只寫\colorbox<3>{yellow}{text}
,但由於某種原因,它使用黑色背景...