3

I would like to get the following items organization:

  • section A
    • category 1
      • item 1.1
      • item 1.2
    • category 2
      • item 2.1
  • section B
    • category 1
      • item 1.3
      • item 1.4
    • category 2
      • item 2.2
      • item 2.3
  • section C
    • category 1
      • item 1.5
    • category 2
      • item 2.4
      • item 2.5
      • item 2.6

with a code like:

\section{A}
\resetcategories
    \nextcategory
        \myitem{}
        \myitem{}
    \nextcategory
        \myitem{}

\section{B}
\resetcategories
    \nextcategory
        \myitem{}
        \myitem{}
    \nextcategory
        \myitem{}
        \myitem{}

\section{C}
\resetcategories
    \nextcategory
        \myitem{}
    \nextcategory
        \myitem{}
        \myitem{}
        \myitem{}

So there is one dynamical item counter within each dynamical category, but its value is saved and it can be resumed even when the category counter is reset.

Is there a neat way to achieve this with custom counters or variables?

3

The common manipulation with TeX registers looks like this:

\newcount\catnum
\expandafter \newcount\csname itemnum1\endcsname
\expandafter \newcount\csname itemnum2\endcsname
\def\inum{itemnum\the\catnum}

\def\bull#1{\noindent\hskip#1\parindent
            \hangindent=#1\parindent
            \llap{$\bullet$\ }\ignorespaces
}
\def\section#1{\par\bull1 \catnum=0 section #1}
\def\nextcategory{\par\advance\catnum by1 \bull2 category \the\catnum}
\def\myitem{\par
   \advance\csname\inum\endcsname by1 \bull3
   item \the\catnum.\expandafter\the\csname\inum\endcsname}
\let\resetcategories=\relax

\section{A}
\resetcategories
    \nextcategory
        \myitem{}
        \myitem{}
    \nextcategory
        \myitem{}

\section{B}
\resetcategories
    \nextcategory
        \myitem{}
        \myitem{}
    \nextcategory
        \myitem{}
        \myitem{}

\section{C}
\resetcategories
    \nextcategory
        \myitem{}
    \nextcategory
        \myitem{}
        \myitem{}
        \myitem{}

\bye
  • I had no idea that such registers existed, thanks! However, your proposition does not work since the last item ends up labeled 2.3 when I run your code whereas it should be 2.6. – iago-lito Feb 17 '16 at 11:40
  • @Iago-lito It was my misunderstanding. I corrected the code. – wipet Feb 17 '16 at 17:08
  • .. which nails it now. Cheers ! ^ ^ – iago-lito Feb 18 '16 at 8:25
3

Something like this perhaps, using 'resuming' enumitem lists?

\documentclass{article}
\usepackage{enumitem}

\newlist{sectionlist}{enumerate}{3}
\setlist[sectionlist,1]{label={\Alph*}}
\setlist[sectionlist,2]{label={\arabic*}}
\setlist[sectionlist,3]{label*={.\arabic*}}


\begin{document}
\begin{sectionlist}
\item Section

  \begin{sectionlist}
  \item Category 
    \begin{sectionlist}[series=first]
    \item Foo
    \item Other Foo
    \end{sectionlist}
  \item Category
    \begin{sectionlist}[series=second]
    \item Foo
    \item Other Foo
    \end{sectionlist}
  \end{sectionlist}

\item Section

  \begin{sectionlist}
  \item Category 

    \begin{sectionlist}[resume=first]
    \item Foo
    \item Other Foo
    \end{sectionlist}

  \item Category 
    \begin{sectionlist}[resume=second]
    \item Foo
    \item Other Foo
    \item Yet another foo
    \end{sectionlist}
  \end{sectionlist}



\item Section

  \begin{sectionlist}
  \item Category 

    \begin{sectionlist}[resume=first]
    \item Foo
    \item Other Foo
    \item Yet another foo
    \end{sectionlist}

  \item Category 
    \begin{sectionlist}[resume=second]
    \item Foo
    \item Other Foo
    \item Yet another foo
    \item Even yet another foo
    \end{sectionlist}
  \end{sectionlist}



\end{sectionlist}


\end{document}

enter image description here

  • I didn't know about this environment either, thanks ! I find it a little bit rigid though, since I need my items to take any form (especially regular text, paragraph with pagebreaking etc). Manipulating registers seems more neat to me. – iago-lito Feb 18 '16 at 8:28
  • @lago-lito: Your decision ;-) Your question wasn't pretty clear in my point of view – user31729 Feb 18 '16 at 13:31

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.