LaTeX forum ⇒ Text Formattingadvanced 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

advanced use of enumerate

Postby ptoche » Wed Nov 04, 2009 7:39 pm

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:

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


Thanks for your help!

Tags:

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
Location: Colombia

Postby gmedina » Wed Nov 04, 2009 11:23 pm

Hi,

the enumitem package offers you a solution:

  1. \documentclass{article}
  2. \usepackage{enumitem}
  3.  
  4. \makeatletter
  5. \def\cstar#1{\expandafter\@cstar\csname c@#1\endcsname}
  6. \def\@cstar#1{\ifcase#1\or $\ast$\or $\ast\ast$\or $\ast\ast\ast$\fi}
  7. \AddEnumerateCounter{\cstar}{\@cstar}{$\ast\ast\ast$}
  8. \makeatother
  9.  
  10. \begin{document}
  11.  
  12. \begin{enumerate}[label=\cstar*\,\arabic*.]
  13. \item first item.
  14. \item second item.
  15. \item third item.
  16. \end{enumerate}
  17.  
  18. \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

Postby ptoche » Thu Nov 05, 2009 1:46 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:
  1. \begin{enumerate}[\label \labelenumi]
  2. \item \label{**} This is a difficult question
  3. \item \label{*} This is an easy question
  4. \item \label{***} This is an impossible question
  5. \end{enumerate}

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

Postby localghost » Thu Nov 05, 2009 2:10 am

Indeed you should have been more precise. Try the following.
  1. \documentclass [11pt,a4paper,english]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage{babel}
  5. \usepackage{tabularx}
  6. \usepackage{blindtext}
  7.  
  8. \newcounter{lineno}
  9.  
  10. \begin{document}
  11. \begin{tabularx}{\linewidth}{@{}r>{\stepcounter{lineno}\thelineno.}rX@{}}
  12. $\ast\ast$ & & \blindtext \\ \\
  13. $\ast\ast\ast$ & & \blindtext \\ \\
  14. $\ast\ast$ & & \blindtext \\ \\
  15. $\ast$ & & \blindtext
  16. \end{tabularx}
  17. \end{document}



Best regards
Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


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

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
Location: Colombia

Postby gmedina » Thu Nov 05, 2009 3:08 am

Here's another option, defining commands \itemone, \itemtwo, and \itemthree to add one, two, and three stars, respectively, before the correponding number:

  1. \documentclass{article}
  2.  
  3. \newcommand\itemone{\stepcounter{enumi}\item[$\ast$\, \theenumi.]}
  4. \newcommand\itemtwo{\stepcounter{enumi}\item[$\ast\ast$\, \theenumi.]}
  5. \newcommand\itemthree{\stepcounter{enumi}\item[$\ast\ast\ast$\, \theenumi.]}
  6.  
  7. \begin{document}
  8.  
  9. \begin{enumerate}
  10. \itemone first item.
  11. \item second item.
  12. \itemone third item.
  13. \itemtwo fourth item.
  14. \itemthree fifth item.
  15. \itemone sixth item.
  16. \end{enumerate}
  17.  
  18. \end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...

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

Postby ptoche » Thu Nov 05, 2009 3:09 am

thanks a lot for your suggestion Thorsten, but I *am* looking for an _enumerate_ solution...

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
Location: Colombia

Postby gmedina » Thu Nov 05, 2009 3:21 am

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

Postby ptoche » Thu Nov 05, 2009 7:27 pm

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

Postby itatitl » Wed Jan 29, 2014 11:51 am

Is it possible to modify this so that it works for various labelling styles?
For example, the current one fails when we try
  1. \begin{enumerate}[(i)]
  2. \item One
  3. \item Two
  4. \itemone Three
  5. \end{enumerate}
Last edited by cgnieder on Wed Jan 29, 2014 12:34 pm, edited 1 time in total.
Reason: added code markup

alainremillard
Posts: 45
Joined: Fri Mar 16, 2012 8:22 pm

Postby alainremillard » Thu Jan 30, 2014 7:25 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
  1. \begin{enumerate}[(i)]
  2. \item One
  3. \item Two
  4. \itemone Three
  5. \end{enumerate}


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

  1. \documentclass{article}
  2.  
  3. \usepackage{enumitem}
  4.  
  5. \newcommand\itemone{\stepcounter{enumi}\item[$\ast$\, \theenumi.]}
  6. \newcommand\itemtwo{\stepcounter{enumi}\item[$\ast\ast$\, \theenumi.]}
  7. \newcommand\itemthree{\stepcounter{enumi}\item[$\ast\ast\ast$\, \theenumi.]}
  8.  
  9. \begin{document}
  10.  
  11. \begin{enumerate}[label=(\roman*)]
  12. \itemone first item.
  13. \item second item.
  14. \itemone third item.
  15. \itemtwo fourth item.
  16. \itemthree fifth item.
  17. \itemone sixth item.
  18. \end{enumerate}
  19.  
  20. \end{document}


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 3 guests