我想自动获得以下效果
\documentclass{beamer}
\definecolor{color1}{RGB}{255,0,0}
\definecolor{color2}{RGB}{0,255,0}
\begin{document}
\begin{frame}
\begin{itemize}
\setbeamercolor{itemize item}{fg=color1}
\item
\setbeamercolor{itemize item}{fg=color2}
\item
\setbeamercolor{itemize item}{fg=color1}
\item
\setbeamercolor{itemize item}{fg=color2}
\item
\end{itemize}
\end{frame}
\end{document}
答案1
我认为通过这种方法你可以实现它:
\documentclass{beamer}
\usepackage{etoolbox}
\definecolor{color1}{RGB}{255,0,0}
\definecolor{color2}{RGB}{0,255,0}
\newcounter{myitem}
\setcounter{myitem}{1}
\renewcommand<>{\item}[1]{\only#2{
\ifnumodd{\themyitem}{%true
\setbeamercolor{itemize item}{fg=color1}\stepcounter{myitem}
}{%false
\setbeamercolor{itemize item}{fg=color2}\stepcounter{myitem}
}
\beameroriginal{\item}{#1}}}
\begin{document}
\begin{frame}
\begin{itemize}
\item text
\item text
\item text
\item text
\end{itemize}
\end{frame}
\end{document}
图形结果:
改进
要激活或禁用替代项目着色,您可以采用如下技巧:
\documentclass{beamer}
\usepackage{etoolbox}
\definecolor{color1}{RGB}{255,0,0}
\definecolor{color2}{RGB}{0,255,0}
\newif\ifitemcolor % <= create a new conditional
\itemcolortrue %<= set it to true to activate the coloring
\newcounter{myitem}
\setcounter{myitem}{1}
\renewcommand<>{\item}[1][]{\only#2{
\ifitemcolor%
\ifnumodd{\themyitem}{%true
\setbeamercolor{itemize item}{fg=color1}\stepcounter{myitem}
}{%false
\setbeamercolor{itemize item}{fg=color2}\stepcounter{myitem}
}\fi%
\beameroriginal{\item}{#1}}}
\begin{document}
\begin{frame}
\begin{columns}
\begin{column}{0.48\textwidth}
\itemcolorfalse %<= set it to false to disable the coloring
\begin{itemize}
\item
\item text
\item text
\item text
\end{itemize}
\end{column}
\begin{column}{0.48\textwidth}
\itemcolortrue %<= set it to true to re-activate the coloring
\begin{itemize}
\item
\item text
\item text
\item text
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\end{document}
在示例中,我创建了两个包含两个列表的列:左侧列表禁用了替代颜色,而右侧列表则未禁用。此外,使用附加项重新定义\item
允许[]
不插入文本,就像两个列表中的前两个元素一样。
图形结果为:
答案2
您还可以拥有两个定义,\item
并在它们之间来回交替。交替着色是通过在环境\AlternateColors
中调用来启用的itemize
。如果没有这个,就会产生默认着色。
\documentclass{beamer}
\definecolor{color1}{RGB}{255,0,0}
\definecolor{color2}{RGB}{0,255,0}
\let\OldItem\item
\newcommand{\itemTwo}{%
\setbeamercolor{itemize item}{fg=color2}\OldItem%
\def\nextitem{\itemOne}%
}%
\newcommand{\itemOne}{%
\setbeamercolor{itemize item}{fg=color1}\OldItem%
\def\nextitem{\itemTwo}%
}%
\newcommand{\nextitem}{\itemOne}%
\newcommand*{\AlternateColors}{%
\def\item{\nextitem}%
}%
\begin{document}
\begin{frame}
\begin{itemize}\AlternateColors% This enables the alternate coloring
\item
\item
\item
\item
\end{itemize}
\end{frame}
\end{document}