4

I want to create an enumerated list, but after the number I want to be able to add a symbol. Right now I can do it with:

\documentclass{article}
\begin{document}
\begin{enumerate}
  \item[1.$\diamondsuit$] First item
  \item[2.$\clubsuit$] Second item
  \item[3.$\spadesuit$] Third item
  \item[4.$\heartsuit$] Fourth item
\end{enumerate}
\end{document

which produces the following

enter image description here

However, in this example I added the numbers by hand. How could I add a symbol after the number, without needing to insert the number manually?

Inserting the symbol after the item, like \item $\diamondsuit$ is not what I want, because the second line will be indented with respect to the number, and not to the bullet, which is "1.diamond".

Clarification I do not want exactly this scheme. I want to be able to chose the symbol to each item, for example: \itemsymbol{$\diamondsuit$} would add the diamond after the corresponding number. (It may be the case for example that 1 and 2 are diamonds, 3 is a spade, etc, or whatever other symbol!)

3 Answers 3

4

With enumitem and \itemsymbol:

\documentclass{article}

\usepackage{enumitem}
\newenvironment{symenum}
 {\enumerate[label=\arabic*.\noexpand\thisenumsymbol,align=left]}
 {\endenumerate}
\newcommand\thisenumsymbol{}
\newcommand\itemsymbol[1]{%
  \renewcommand{\thisenumsymbol}{#1}%
  \item
}

\begin{document}
\begin{symenum}
  \itemsymbol{$\diamondsuit$}\label{first} First item
  \itemsymbol{$\clubsuit$} Second item
  \itemsymbol{$\spadesuit$} Third item
  \itemsymbol{$\heartsuit$} Fourth item
  \itemsymbol{} Fourth item
\end{symenum}

Here's the reference: \ref{first}
\end{document}

enter image description here

3
  • This is much better than the other solution. It allows me to move the items without having to check whether I put it in a section with a symbol or another. The symbol is right in the item. Thanks! Apr 23, 2015 at 17:48
  • I would add \newcommand\refsymbol[1]{\renewcommand{\thisenumsymbol}{}\ref{#1}} to be able to reference an item without carrying the symbol ;-) Apr 23, 2015 at 18:02
  • 1
    @AlejandroDC Fixed, you can use \ref. If you don't want to carry the symbol, add ,ref=\arabic*. to the optional argument to enumerate in the definition.
    – egreg
    Apr 23, 2015 at 18:08
3
\documentclass{article}
\def\zz#1{%
\ifcase#1\relax\or$\diamondsuit$\or$\clubsuit$\or$\spadesuit$\or$\heartsuit$\else?\fi}

\begin{document}
\renewcommand\labelenumi{\theenumi.\zz{\value{enumi}}}
\begin{enumerate}
  \item First item
  \item Second item
  \item Third item
  \item Fourth item
\end{enumerate}
\end{document}
5
  • David, when I see code like this I realize I still know very little. Is there some documentation that would help me understand this code?
    – Alenanno
    Apr 23, 2015 at 15:55
  • @Alenanno The \ifcase in \zz is just the same as you see \alph or \ftnsymbol or any of the latex counter types other than arabic or roman, \label... is the macro use to print labels in enumerate. Probably one of the more readable documentation of those parameters is the enumitem package (which also gives an easier syntax for setting them as the other answer shows) Apr 23, 2015 at 16:07
  • This solution is static. What I want is to chose what symbol to add to what item (the main idea is that I want to mark the items with different symbols, it may be the case that 1 and 2 are diamonds, 3 is a spade, etc.). Apr 23, 2015 at 16:49
  • @AlejandroDC I'd never have guessed that from the question:-) Apr 23, 2015 at 17:43
  • Sorry. My bad. Anyway, your solution helped to the final solution :-) Apr 23, 2015 at 17:46
2

An alternative using enumitem.sty:

\documentclass{article}
\usepackage{enumitem}
\makeatletter
\def\ctext#1{\expandafter\@ctext\csname c@#1\endcsname}
\def\@ctext#1{\ifcase#1\or $\diamondsuit$\or 
  $\clubsuit$\or $\spadesuit$\or$\heartsuit$\or ?\fi}
\makeatother
\AddEnumerateCounter{\ctext}{\@ctext}{MyWidth}

\begin{document}
\begin{enumerate}[label=\arabic*.\ctext{enumi}]
\item foo
\item bar
\item baz
\item foobar
\end{enumerate}
\end{document}

EDIT 1: After clarification of OP

A dynamic approach based on David's solution:

\documentclass{article}
\usepackage{enumitem}
\def\switchenum#1{%
  \renewcommand\labelenumi{\theenumi.#1}%
}

\begin{document}
\begin{enumerate}[align=left]
  \switchenum{$\heartsuit$}
  \item First item  \switchenum{$\diamondsuit$}
  \item Second item 
  \item Third item  \switchenum{$\clubsuit$}
  \item Fourth item \switchenum{}
  \item Fifth item
\end{enumerate}
\end{document}
2
  • This solution is static. What I want is to chose what symbol to add to what item when I create the enumeration (the main idea is that I want to mark the items with different symbols, it may be the case that 1 and 2 are diamonds, 3 is a spade, etc.). Apr 23, 2015 at 16:55
  • After the edit: Just amazing. This is exactly what I was looking for. Thanks! Apr 23, 2015 at 17:37

You must log in to answer this question.

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