Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

i would like to obtain the following effect automatically

\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}

enter image description here

share|improve this question

2 Answers 2

up vote 8 down vote accepted

I think with this approach you can get it:

\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}

Graphical result:

enter image description here

IMPROVEMENT

To activate or disable the alternate item coloring you can adopt a trick like this one:

\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}

In the example I created two columns with two lists: the list on the left has the alternate coloring disabled while the list on the right does not. Moreover the re-definition of the \item with additional [] allows to not insert text, as did for the two first elements in both the lists.

The graphical result is:

enter image description here

share|improve this answer
    
i had to add an empty default value to the \renewcommand<> so it becomes \renewcommand<>{\item}[1][]{\only#2{. is it ok like this? should the answer be updated? –  capitalaslash May 30 '12 at 13:25
    
It depends of what you have in mind.. I don't know why you need a default value in this case; maybe do you want sometime use this coloring an other time the standard provided by the theme? –  Claudio Fiandrino May 30 '12 at 14:34
    
it did not compile without the additional [] –  capitalaslash May 30 '12 at 15:36
    
I think you should be more clear telling which is your purpose; if it is, as I guess, having the possibility of disable the coloring, using square braces in my code is not the right way. At least, it is not as I will do. I can not say more without knowing your purposes, sorry. –  Claudio Fiandrino May 30 '12 at 15:40
    
i had no particular purpose. your original solution did not work in my example since the \items were empty, but this is not a real case. with the additional [] in the macro definition it also worked with empty \items, but i don't know enough tex-foo to understand why. –  capitalaslash May 31 '12 at 7:08

Yo can also have two definitions of the \item and altermnate back and forth between them. The alternating coloring is enabled via \AlternateColors called within the itemize environment. Without this, the default coloring is produced.

\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}
share|improve this answer
    
your solution misses the <> beamer stuff. will it work with them too? –  capitalaslash May 31 '12 at 7:10
    
Sadly, I know almost nothing about beamer - never used it. Best I can recommend is that you try it out. If you post a MWE, I am will test it and try to resolve any issues. –  Peter Grill May 31 '12 at 7:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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