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.

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}
share|improve this question
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. –  David Carlisle Sep 27 '12 at 15:59
1  
and David Carlisle's link also points to tex.stackexchange.com/questions/52715/… –  cmhughes Sep 27 '12 at 16:00
add comment

1 Answer

up vote 4 down vote accepted

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

share|improve this answer
    
Yes, I figured it out after playing around with your code. Just couldn't post an answer. –  azetina Sep 27 '12 at 19:27
add comment

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.