2

I would like to have a itemize list using several different item colors, at least three. Basically something like described here taking the direction Alan Munn suggested:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}
\newif\ifgooditem
\gooditemtrue
\newcommand\gooditem{\gooditemtrue\item}
\newcommand\baditem{\gooditemfalse\item}
\begin{document}
\begin{itemize}[label={\ifgooditem\color{green}\else\color{red}\fi\textbullet}]
\gooditem A good item
\baditem A bad item
\end{itemize}
\end{document}

Just that I want to have at least a third class, for example \neutralitem. How can this be done? I tried

\newif\ifgooditem
\gooditemtrue
\newif\ifneutralitem
\neutralitemtrue
\newcommand\gooditem{\gooditemtrue\item}
\newcommand\neutralitem{\gooditemfalse\item}
\newcommand\baditem{\gooditemfalse\baditemtrue\neutralitemfalse\item}

and

[label={\ifgooditem\color{green}\ifbaditem\color{red}\else\color{black}\fi\textbullet}]

but it doesn't seem to work.

2 Answers 2

2

You can try this:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}

\newif\ifgooditem
\newif\ifneutralitem
\newif\ifbaditem
\newcommand\gooditem{\gooditemtrue\baditemfalse\neutralitemfalse\item}
\newcommand\neutralitem{\neutralitemtrue\gooditemfalse\baditemfalse\item}
\newcommand\baditem{\baditemtrue\gooditemfalse\neutralitemfalse\item}

\begin{document}
\begin{itemize}[label={
  \ifgooditem\color{green}\fi
  \ifbaditem\color{red}\fi
  \ifneutralitem\color{black}\fi
  \textbullet}]
\neutralitem A neutral item
\gooditem A good item
\baditem A bad item
\gooditem A good item
\baditem A bad item
\neutralitem A neutral item
\end{itemize}
\end{document}

enter image description here

2

More flexible solution would be a command that tests for a variable, i did this using the package ifthen for the string comparison.

\documentclass{article}

\usepackage{ifthen}
\usepackage{enumitem}
\usepackage{xcolor}

\newcommand{\itemclass}{}
\newcommand{\myitem}[1]{%
  \renewcommand{\itemclass}{#1}\item%
}
\newcommand{\mylabel}{%
\ifthenelse{\equal{\itemclass}{bad}}{\color{red}\textbullet}{%
\ifthenelse{\equal{\itemclass}{good}}{\color{green}\textbullet}{%
\ifthenelse{\equal{\itemclass}{neutral}}{\color{black}\textbullet}{}}}%
}

\begin{document}
\begin{itemize}[label=\mylabel]
      \myitem{good} green
      \myitem{bad} red 
      \myitem{neutral} black
  \end{itemize}
\end{document}
1
  • Thanks, that's also a very good approach to consider - especially if there are several lists with the same format. One thing which I'm still missing (as in the other approach) is the possibility to still add "\item" entries (in the midst of all the customized stuff) with the default format.
    – BThomas
    Commented Nov 13, 2014 at 7:00

You must log in to answer this question.

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