2

Several posts describe the coloration of single items (text and item label); however, these solutions do not work in beamer documents. For instance, following this post, expected results are obtained for articles but not beamer frames:

article:

\documentclass{article}
\usepackage{xcolor}

\newcommand\itemcolor[2]{%
\begingroup%
\color{#1}%
\item #2%
\endgroup}

\begin{document}
    \begin{enumerate}
        \item first
        \itemcolor{red}{second}
        \item third
        \begingroup
            \color{red}
            \item fourth
        \endgroup
        \item fifth
    \end{enumerate}
\end{document}

enter image description here

beamer:

\documentclass{beamer}
\usepackage{xcolor}

\setbeamercolor{structure}{fg=black}

\newcommand\itemcolor[2]{%
\begingroup%
\color{#1}%
\item #2%
\endgroup}

\begin{document}
\begin{frame}
    \begin{enumerate}
        \item first
        \itemcolor{red}{second}
        \item third
        \begingroup
            \color{red}
            \item fourth
        \endgroup
        \item fifth
    \end{enumerate}
\end{frame}
\end{document}

enter image description here

Note that \setbeamercolor{structure}{fg=black} was used to avoid having the default purple color for the item number, but the effect is the same if that line is omitted (the color of the item number being uniformly purple instead of the designated color).

How can the result for \documentclass{article} be realized for \documentclass{beamer} (i.e., coloration of the item label in addition to the item text)? And what is the reason for the discrepancy in behavior between the two document classes?

3

Using a combination of this answer and that answer one may do

\documentclass{beamer}

\setbeamercolor{structure}{fg=black}
\newcommand\itemcolor[2]{%
\setbeamercolor{enumerate item}{fg=#1}\item \textcolor{#1}{#2}
\setbeamercolor{enumerate item}{fg=black}}

\begin{document}
\begin{frame}
    \begin{enumerate}
        \item first
        \itemcolor{red}{second}
        \item third
        \begingroup
            \color{red}
            \item fourth
        \endgroup
        \item fifth
    \end{enumerate}
\end{frame}
\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.