4

I'm trying to create a list of the following type:

1a) Apples

1b) Bananas

1c) Oranges

2a) Tomatoes

2b) Carrots

3) Bread

4a) Cake

4b) Cookies

I tried to use both enumitem and easylist and read some answers of related questions, but I wasn't successful.

  • 4
    Could you please show what you tried so far? Will there also be a "parent" to 1a), 1b) and 1c)? – leandriis Apr 1 at 7:55
  • If had "parents" then it would be easy to do it with easylist. The point is that I don't – Gil Apr 1 at 9:31
  • What is the question? – Peter Mortensen Apr 1 at 15:59
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Alessandro Cuttin Apr 1 at 18:16
9

The proposed syntax is

  • a simple \item steps the main counter and just uses it;
  • \item[+] steps the main counter and prints it followed by the secondary one;
  • \item[=] only steps the secondary counter.
\documentclass{article}
\usepackage{xparse}

\newcounter{bienumi}
\newcounter{bienumii}[bienumi]
\renewcommand{\thebienumi}{%
  \arabic{bienumi}\ifnest\alph{bienumii}\fi
}
\newif\ifnest

\newenvironment{bienum}{\enumerate\let\item\biitem}{\endenumerate}

\ExplSyntaxOn\makeatletter
\NewDocumentCommand{\biitem}{o}
 {
  \nesttrue
  \IfNoValueTF{#1}
   {
    \nestfalse
    \stepcounter{bienumi}
   }
   {
    \str_case:nn {#1}
     {
      {+}{\stepcounter{bienumi}\stepcounter{bienumii}}
      {=}{\stepcounter{bienumii}}
     }
   }
  \@item[\thebienumi)]
 }
\makeatother\ExplSyntaxOff

\begin{document}

\begin{bienum}
\item[+] Apples

\item[=] Bananas

\item[=] Oranges

\item[+] Tomatoes

\item[=] Carrots

\item Bread

\item[+] Cake

\item[=] Cookies
\end{bienum}

\end{document}

enter image description here

| improve this answer | |
  • You made the things so easy....Greetings.... – MadyYuvi Apr 1 at 9:05
  • I confess that it's a complete black box for me, but it works beautifully! Thanks so much! – Gil Apr 1 at 9:32
  • BTW I hope you're safe there in Italy! – Gil Apr 1 at 9:37
  • @Gil Staying at home as much as possible. Thanks for caring! – egreg Apr 1 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.