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?

1
  • You don't need \usepackage{xcolor} in your presentation, beamer already load this for you. Aug 25, 2018 at 12:43

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .