使用 beamer,我想根据传递的参数更改 itemize 项目符号的颜色,例如
\begin{myitemize}
\item[red] no
\item[green] yes
\end{myitemize}
有什么办法可以实现吗?我一直在谷歌搜索,但没有成功...
答案1
需要重新定义\makelabel
\documentclass{beamer}
\usetheme{Frankfurt}
\setbeamertemplate{itemize item}[triangle]
\newcommand\Item[1][blue]{%
\gdef\makelabel##1{{%
\hss\llap{{%
\usebeamerfont*{itemize \beameritemnestingprefix item}%
\color{#1}##1}}}}
\item }
\begin{document}
\begin{frame}{foo}{bar}
\begin{itemize}[<+->]
\Item[red] red
\Item[blue] blue
\end{itemize}
\end{frame}
\end{document}
答案2
与 Herbert 的解决方案类似。此解决方案不使用内部宏,但不适用于覆盖。
\documentclass{beamer}
\usetheme{Frankfurt}
\begingroup
\usebeamercolor{itemize item}
\xglobal\colorlet{itemizefg}{fg}
\endgroup
\newcommand*\citem[1][itemizefg]{%
\setbeamercolor{item projected}{bg=#1}\item}
\begin{document}
\begin{frame}{Foo}{bar}
\begin{itemize}
\citem blue
\citem[red] red
\citem blue
\end{itemize}
\end{frame}
\end{document}
以下是使用覆盖的修订解决方案。我更改了请求的语法:
\documentclass{beamer}
\usetheme{Frankfurt}
\colorlet{myitem}{red}
\newenvironment{icolorenv}{%
\begin{altenv}%
{\usebeamertemplate{alerted text begin}
\setbeamercolor{alerted text}{fg=myitem}
\usebeamercolor{alerted text}}
{\usebeamertemplate{alerted text end}}
{\color{.}}{}}
{\end{altenv}}
\newcommand{\icolor}[2]{\seticolor{#1}%
\begin{icolorenv}#2\end{icolorenv}}
\newcommand{\seticolor}[1]{\xglobal\colorlet{myitem}{#1}}
\begin{document}
\begin{frame}{Foo}{bar}
\begin{itemize}
\item blue\pause
\icolor{green}{\item green}\pause
\item blue\pause
\end{itemize}
\begin{itemize}[<+->]
\item blue
\seticolor{orange}\item<+-|icolor@+-> orange
\item green
\end{itemize}
\end{frame}
\end{document}