3

I'm working on a document with several chapters. In the end of each chapter I have tasks which I want to enumerate as 101, 102, ... ,112 (chapter 1), 201, 202, ... 212 (chapter 2) and so on.

For now, my solution is use of the packages enumitem and etoolbox and the \setlist command:

Updated code, a small document illustrating the problem

\documentclass{report}
\usepackage{enumitem}
\usepackage{etoolbox}

\setlist[enumerate]{label=\thechapter 0\arabic{*}.,resume}

% restart the enumerate list every chapter
 \preto\chapter{
   \restartlist{enumerate}
}

\title{Running enumeration according to chapters}

\begin{document}

\chapter{First Chapter}
\section{Tasks Chapter \thechapter}
\begin{enumerate}
    \item Task 1
    \item Task 2
    \item Task 3
    \item Task 4
    \item Task 5
    \item Task 6
    \item Task 7
    \item Task 8
    \item Task 9
    \item Task 10
\end{enumerate}

\chapter{Second chapter}
\section{Tasks Chapter \thechapter}
\begin{enumerate}
    \item Task 1
    \item Task 2
    \item Task 3
    \item Task 4
    \item Task 5
    \item Task 6
    \item Task 7
    \item Task 8
    \item Task 9
    \item Task 10
\end{enumerate}

\end{document}

This works for enumeration up to 109, 209 and so on, but the 10:th task will be labeled 1010, 2010 and so on.

How can I achieve that kind of enumeration which will use no more (and no less) than two positions for the running numbering and the leftmost position for the chapters?

2
  • 1
    As always on this site, please extend your sniplet to a full but minimal document. That makes it a lot easier for others to test your code. Besides this, it is a really good question, as it is not clear how to gain access to the actual value of the counter in the list
    – daleif
    Commented Jun 14, 2023 at 11:17
  • 1
    Why not rely on e-TeX arithmetics ? and set something like \setcounter{enumi}{numexpr 100*\value{chapter}\relax} at the start of enumerate. No need to customize label and works both with and without enumitem
    – Jhor
    Commented Jun 14, 2023 at 11:30

1 Answer 1

1

As suggested by Jhor, you can use this code :

\documentclass{report}

\title{Running enumeration according to chapters}

\begin{document}

\chapter{First Chapter}

\section{Tasks Chapter \thechapter}

\begin{enumerate}
\setcounter{enumi}{\numexpr 100*\value{chapter}\relax}
    \item Task 1
    \item Task 2
    \item Task 3
    \item Task 4
    \item Task 5
    \item Task 6
    \item Task 7
    \item Task 8
    \item Task 9
    \item Task 10
\end{enumerate}

\chapter{Second chapter}
\section{Tasks Chapter \thechapter}
\begin{enumerate}
\setcounter{enumi}{\numexpr 100*\value{chapter}\relax}
    \item Task 1
    \item Task 2
    \item Task 3
    \item Task 4
    \item Task 5
    \item Task 6
    \item Task 7
    \item Task 8
    \item Task 9
    \item Task 10
\end{enumerate}

\end{document}

And if you prefer, you can create a new environnement :

\documentclass{report}

\title{Running enumeration according to chapters}

\newenvironment{chapenumerate}
{
\begin{enumerate}
\setcounter{enumi}{\numexpr 100*\value{chapter}\relax}
}
{
\end{enumerate}
}

\begin{document}

\chapter{First Chapter}
\section{Tasks Chapter \thechapter}

\begin{chapenumerate}
    \item Task 1
    \item Task 2
    \item Task 3
    \item Task 4
    \item Task 5
    \item Task 6
    \item Task 7
    \item Task 8
    \item Task 9
    \item Task 10
\end{chapenumerate}

\chapter{Second chapter}
\section{Tasks Chapter \thechapter}

\begin{chapenumerate}
    \item Task 1
    \item Task 2
    \item Task 3
    \item Task 4
    \item Task 5
    \item Task 6
    \item Task 7
    \item Task 8
    \item Task 9
    \item Task 10
\end{chapenumerate}

\end{document}
2
  • This should be transform into a dedicated environment. Don't you think?
    – projetmbc
    Commented Jun 14, 2023 at 12:23
  • 2
    I edited the answer Commented Jun 14, 2023 at 12:43

You must log in to answer this question.

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