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}
2
  • 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 tex.stackexchange.com/questions/70436/… 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. Commented Sep 27, 2012 at 15:59
  • 1
    and David Carlisle's link also points to tex.stackexchange.com/questions/52715/…
    – cmhughes
    Commented Sep 27, 2012 at 16:00

1 Answer 1

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

1
  • Yes, I figured it out after playing around with your code. Just couldn't post an answer.
    – azetina
    Commented Sep 27, 2012 at 19:27

You must log in to answer this question.

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