リスト内のアイテムを発見したらハイライト表示します

リスト内のアイテムを発見したらハイライト表示します
\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は項目別リストを表示しました。2つの連続した項目が表示された後、2番目の項目が強調表示されることを期待しています。第三段階でフレームを複製することでこれを達成しました。フレームを手動で複製せずにオーバーレイでこれを実現できますか?

答え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テキストの周囲の一部を塗りつぶすため、間隔が変わり、目に見えるジャンプが発生します (実際に試して確認してください)。

これを修正するには、常に を使用し\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<>のセクションbeamer9.6.1 コマンドと環境をオーバーレイ仕様に対応させる最初の引数は定義するマクロの名前 (\mycolorboxこの場合は ) で、その後にオーバーレイ指定を除く引数の数が続き、最後に最初の引数のデフォルト値が続きます。コマンド内では、引数は#文字とその番号を使用して参照できます (#1など#2、コメントを参照してください)。

二重の中括弧{{とのペア}}は TeX グループを作成するために存在します。これは、マクロの (再) 定義が最後に忘れられることを意味します。外側のペアはコマンドの内容を区切り、内側のペアは TeX グループです。

次に、\def( を使用することもできます) を使用して、最初はデフォルトの色である\newcommand新しいマクロ を定義します。 次に、 を使用して、条件付きでそれを目的の色 (この例では黄色) に再定義します。 最後に、 コマンドを呼び出します。\mycolor\only\colorbox

ちなみに、 と書くこともできます\colorbox<3>{yellow}{text}が、なぜか背景が黒になっています...

関連情報