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.

Usually, when you have the following document:

\documentclass{article}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}
\item Mary
\item[had] a little 
\item lamb
\end{enumerate}
\end{document}

It will format as

  1. Mary
had a little
  2. lamb

I would want it to format as

  1. Mary
  2 (had). a little
  3. lamb

In other words, I would like the optional argument that can be passed to an \item not to replace the usual label, but I want it to appear additionally. In particular, the counter should still be stepped.

This might seem like a subtlety, but note that the argument should appear before the period and after the counter. In fact, this is just a minimal example - I would like to have greater flexibility in placing the optional argument within the label.

Is there a way to do this with the enumitem package?

share|improve this question
3  
A simple solution would be \item (had) a little, but perhaps that is not an option. –  Peter Grill Mar 8 '13 at 8:09
    
What about references? How should item 2 be referenced? With 2 or with 2(had)? –  egreg Mar 8 '13 at 8:34
    
Just with 2, as in, with the usual counter value. –  Jesko Hüttenhain Mar 8 '13 at 8:51
    
It would be interesting to know why you don't just do it as Peter Grill suggests. Could you please add that to the question? Thanks! –  Hendrik Vogt Mar 8 '13 at 13:37
    
It's basically in the comment to Peters answer, but I put it in the original question as well. –  Jesko Hüttenhain Mar 9 '13 at 0:10
add comment

2 Answers

up vote 3 down vote accepted

You could try it this way:

\documentclass{article}
\usepackage{enumitem}
\newcommand\labeltext{}
\newcommand\specialitem[1][]{%
 {\renewcommand\labeltext{ (#1)}\item\leavevmode}}
\begin{document}
\begin{enumerate}[label=\arabic*\noexpand\labeltext.]
\item Mary
\specialitem[had] a little 
\item lamb
\end{enumerate}
\end{document}

Remarks:

  1. I'm using a special command but it should also be possible to patch \item but then you would loose the standard behaviour.

  2. The correct alignment of the label is left as an exercise ;-).

share|improve this answer
    
That's clever! Also, it does exactly what I want. Also, exercise solved. Thanks a bunch! =) –  Jesko Hüttenhain Mar 9 '13 at 0:08
    
I do not fully understand, what you do, so it might be superfluous, but: Jesko writes in a comment to egreg above, that for the references he wants only the counters without the added text. In enumitem for such cases exists an option ref, here I would suggest ref=\arabic*.. –  Speravir Mar 9 '13 at 3:51
    
No no, don't worry, this is precisely what I wanted. I am using cleveref anyway. –  Jesko Hüttenhain Mar 9 '13 at 15:25
add comment

You can define you own custom environment in which you redefine \item macro:

enter image description here

Notes:

  • If you wish to redefine a macro that has optional parameters, you have to use \LetLtxMacro from the letltxmacro package . A detailed description of \LetLtxMacro can be found at this question at When to use \LetLtxMacro?.

  • I have used the xstring package for string comparison as I prefer its syntax, but this can be done without that pacakge if required.

Code:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xstring}
\usepackage{letltxmacro}

\LetLtxMacro{\OldItem}{\item}
\newenvironment{MyEnumerate}[1][]{%
    \renewcommand{\item}[1][]{\OldItem \IfStrEq{##1}{}{}{(##1)}}%
    \begin{enumerate}[#1]%
}{%
    \end{enumerate}%
}%

\begin{document}
\begin{MyEnumerate}
    \item Mary
    \item[had] a little 
    \item lamb
\end{MyEnumerate}
\end{document}
share|improve this answer
2  
This might seem like a subtlety, but I would want the argument to appear before the period and after the counter. More precisely, I would like to have greater flexibility in placing the optional argument within the label. –  Jesko Hüttenhain Mar 8 '13 at 8:23
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.