4

The following code is very interesting as it adds an asterisk beside an enumeration.

\documentclass{article}
\usepackage{enumitem} 
%%%%%%%%%%%%%%%%%%%%%%%%
%% CODE thanks to egreg 
%%%%%%%%%%%%%%%%%%%%%%%
\setlist[enumerate]{before=\setupmodenumerate}

\newif\ifmoditem
\newcommand{\setupmodenumerate}{%
  \global\moditemfalse
  \let\origmakelabel\makelabel
  \def\moditem##1{\global\moditemtrue\def\mesymbol{##1}\item}%
  \def\makelabel##1{%
    \origmakelabel{\ifmoditem\llap{\mesymbol\enspace}\fi##1}%
    \global\moditemfalse}%
}

\begin{document}
\begin{enumerate}
\moditem{*} test
\end{enumerate}
\end{document}

This yields:

enter image description here

My question is:

"How can I create a similar modded item, say \citem, that colours the enumeration?"

A similar code or using the idea as above would be great. Note that the colouring (what the user wishes to be) must be to selective items and not the entire set of enumeration.


UPDATE: So looking at the links above I thought I had the solution as the code;

\newcommand{\myitem}{\refstepcounter{enumi}\item[\color{red}{\theenumi.}]}

sheds some light, but it does not respect enumeration within enumeration. Hmmmmmm???

enter image description here

This is given by

\begin{enumerate}
\myitem
\moditem{*} test
\myitem
\myitem Test test test
    \begin{enumerate}
    \item
    \item 
    \item 
    \myitem 
    \end{enumerate}
\end{enumerate}
azetina
  • 28,884
  • 2
    That's actually quite hard as (unlike the asterisk) you need to locate the end of the item which isn't so easy with the standard latex list markup. You could look at the solutions for http://tex.stackexchange.com/questions/70436/enclose-an-entry-in-an-enumerate-list-in-parentheses and use colour rather than parenthesis, although an alternative to locating the end would be to use \color every item, setting to black in the default case. – David Carlisle Sep 27 '12 at 15:59
  • 1
    and David Carlisle's link also points to http://tex.stackexchange.com/questions/52715/modifying-labels-on-some-enumerated-items/ – cmhughes Sep 27 '12 at 16:00

1 Answers1

5

Just change the macros to use color:

\documentclass{article}
\usepackage{enumitem,color} 

\setlist[enumerate]{before=\setupmodenumerate}

\newif\ifcitem
\newcommand{\setupmodenumerate}{%
  \global\citemfalse
  \let\origmakelabel\makelabel
  \def\citem##1{\global\citemtrue\def\cecolor{##1}\item}%
  \def\makelabel##1{%
    \origmakelabel{\ifcitem\color{\cecolor}\fi##1}%
    \global\citemfalse}%
}

\begin{document}
\begin{enumerate}
\item
\citem{red} test
\item
\item Test test test
    \begin{enumerate}
    \item
    \citem{green} 
    \item 
    \item 
    \end{enumerate}
\end{enumerate}
\end{document}

enter image description here

egreg
  • 1,121,712