## LaTeX forum ⇒ Text Formatting ⇒ advanced use of enumerate Topic is solved

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
ptoche
Posts: 49
Joined: Thu Apr 12, 2007 10:41 am

I'd like to produce an _enumerate_ list with a custom number of stars placed to the left of the enumerate label, like this:

* 1. This is an easy question
** 2. This is a difficult question
*** 3. This is an impossible question

I know how to place one star everywhere (or indeed two or three stars), using the _enumerate_ package, but I do not know how to alternate the number of stars:

\usepackage{enumerate}\begin{enumerate}[*]\item This is an easy question and gets 1 star\item This is a difficult question and should get 2 stars, but only gets 1 as it is...\item This is an impossible question and should get 3 stars, but only gets 1 as it is...\end{enumerate}

Tags:

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
Hi,

the enumitem package offers you a solution:

\documentclass{article}\usepackage{enumitem} \makeatletter   \def\cstar#1{\expandafter\@cstar\csname c@#1\endcsname}   \def\@cstar#1{\ifcase#1\or $\ast$\or $\ast\ast$\or $\ast\ast\ast$\fi}   \AddEnumerateCounter{\cstar}{\@cstar}{$\ast\ast\ast$}\makeatother \begin{document} \begin{enumerate}[label=\cstar*\,\arabic*.]   \item first item.   \item second item.   \item third item.\end{enumerate} \end{document}

Please refer to the package documentation for further information.
1,1,2,3,5,8,13,21,34,55,89,144,233,...

ptoche
Posts: 49
Joined: Thu Apr 12, 2007 10:41 am
thanks a lot for your suggestion, it's pretty close. Let me clarify what I'm looking for.

I want to have an _enumerate_ list where some items will be preceded by one star, others by two stars, etc. but I need to retain the ability to specify how many stars to be assigned to each individual item -- the 1 2 3 pattern apparent in my example was a fluke. How can I do something like:

* 1. This is an easy question
*** 2. This is an impossible question
* 3. This is an easy question
** 4. This is a difficult question
*** 5. This is an impossible question
** 6. This is a difficult question
** 7. This is a difficult question
* 8. This is an easy question

I guess I would need to have a _label_ inside each _item_ to specify how many stars are to be assigned to it, then the _enumerate_ environment would need to be told how to print the content of the _label_ next to the standard _enumerate_ _label_, perhaps something along the lines of:
\begin{enumerate}[\label \labelenumi]\item \label{**} This is a difficult question \item \label{*} This is an easy question\item \label{***} This is an impossible question\end{enumerate}

localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Indeed you should have been more precise. Try the following.
\documentclass [11pt,a4paper,english]{article}\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage{babel}\usepackage{tabularx}\usepackage{blindtext} \newcounter{lineno} \begin{document}   \begin{tabularx}{\linewidth}{@{}r>{\stepcounter{lineno}\thelineno.}rX@{}}     $\ast\ast$ & & \blindtext \\ \\     $\ast\ast\ast$ & & \blindtext \\ \\     $\ast\ast$ & & \blindtext \\ \\     $\ast$ & & \blindtext   \end{tabularx}\end{document}

Best regards
Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
Here's another option, defining commands \itemone, \itemtwo, and \itemthree to add one, two, and three stars, respectively, before the correponding number:

1,1,2,3,5,8,13,21,34,55,89,144,233,...

ptoche
Posts: 49
Joined: Thu Apr 12, 2007 10:41 am
thanks a lot for your suggestion Thorsten, but I *am* looking for an _enumerate_ solution...

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
ptoche wrote:thanks a lot for your suggestion Thorsten, but I *am* looking for an _enumerate_ solution...

Perhaps you didn´t notice my previous reply?
1,1,2,3,5,8,13,21,34,55,89,144,233,...

ptoche
Posts: 49
Joined: Thu Apr 12, 2007 10:41 am
Dear gmedina,

I hadn't seen your message! According to my clock, your message was posted at 10:08am, while mine was posted at 10:09am!

Your code is *exactly* what I was looking for. I am ever so grateful for your help. I can see ways to apply the idea to other uses too, great stuff. The first piece of code you posted could come in handy one day too, always useful to have.

Thank you very much,

itatitl
Posts: 13
Joined: Thu Mar 24, 2011 8:20 am
Is it possible to modify this so that it works for various labelling styles?
For example, the current one fails when we try
\begin{enumerate}[(i)]\item One\item Two\itemone Three\end{enumerate}
Last edited by cgnieder on Wed Jan 29, 2014 12:34 pm, edited 1 time in total.

alainremillard
Posts: 45
Joined: Fri Mar 16, 2012 8:22 pm
itatitl wrote:Is it possible to modify this so that it works for various labelling styles?
For example, the current one fails when we try
\begin{enumerate}[(i)]\item One\item Two\itemone Three\end{enumerate}

Have a look at the enumitem package. It allows customization of enumerate environment.
