# item counter within enumerate

I want to customize items from a list within the enumerate environment, using a counter that is followed up in each list.

Here's how I did it:

\documentclass{article}
\usepackage{enumitem}

\begin{document}

\newcounter{counter}

List 1

\begin{enumerate}[label=Ex.\arabic{counter}] \stepcounter{counter}
\item Some text \stepcounter{counter}
\item Some text \stepcounter{counter}
\item Some text \stepcounter{counter}
\end{enumerate}

List 2

\begin{enumerate}[label=Ex.\arabic{counter}] \stepcounter{counter}
\item Some text \stepcounter{counter}
\item Some text \stepcounter{counter}
\item Some text \stepcounter{counter}
\end{enumerate}

\end{document}


Another way to do it is by customizing each item:

\documentclass{article}
\usepackage{enumitem}

\begin{document}

\newcounter{counter}

List 1

\begin{enumerate}
\item[Ex.\stepcounter{counter}\arabic{counter}] Some text
\item[Ex.\stepcounter{counter}\arabic{counter}] Some text
\item[Ex.\stepcounter{counter}\arabic{counter}] Some text
\end{enumerate}

List 2

\begin{enumerate}
\item[Ex.\stepcounter{counter}\arabic{counter}] Some text
\item[Ex.\stepcounter{counter}\arabic{counter}] Some text
\item[Ex.\stepcounter{counter}\arabic{counter}] Some text
\end{enumerate}

\end{document}


As you can see, the only way I can stepcounter each item is by using the command every time I create a new item. However, I want to avoid using the same command every time and just define from the begining that each item should step the counter, I'm looking to do something like this:

\begin{enumerate}[label=\stepcounter{counter}Ex.\arabic{counter}]
\item Some text
\item Some text
\item Some text
\end{enumerate}


But that doesn't work.

Also, if possible, I'd like to avoid creating a new command for "item" such as

\newcommand{\newitem}{\item[\stepcounter{counter}Ex.\arabic{counter}]}


Because I might neeed to create a list that shouldn't follow the same count.

Also I know I can delimit from which number to start like this:

List 1

\begin{enumerate}[label=Ex.\arabic*]
\item Some text
\item Some text
\item Some text
\end{enumerate}

List 2

\begin{enumerate}[label=Ex.\arabic*, start=4]
\item Some text
\item Some text
\item Some text
\end{enumerate}


But I want to avoid that too, though maybe it is much to ask.

Thank you

• Erh did you read the enumitem manual? label=Ex. \arabic* seems to do what you want Dec 16, 2021 at 22:54
• The problem is everytime I create a new list the count resets, and I know I can delimit from which number to start, but I wanted to avoid that too. Thanks. Dec 16, 2021 at 22:55
• That is not clear from your question, please rephrase Dec 16, 2021 at 22:57

Use \arabic* - enumitem's way of using the appropriate counter formatting:

\documentclass{article}

\usepackage{enumitem}

\begin{document}

\begin{enumerate}[label=Ex.\arabic*]
\item Some text
\item Some text
\item Some text
\end{enumerate}

\end{document}


You may be better off defining your own list type, which could include the resume option to resume counting if you break up your list with interspersed text.

\documentclass{article}

\usepackage{enumitem}
\newlist{exercises}{enumerate}{1}
\setlist[exercises]{%
label=Ex.\arabic*,
resume
}

\begin{document}

\begin{exercises}
\item Some text
\item Some text
\item Some text
\end{exercises}

Some text in between the two lists.

\begin{exercises}
\item Some text
\item Some text
\item Some text
\end{exercises}

\end{document}

• The problem is everytime I create a new list the count resets, and I know I can delimit from which number to start, but I wanted to avoid that too. Thanks. Dec 16, 2021 at 22:55
• @Darvid: I've updated the answer to include a solution to your new problem (of resuming a list that may have been broken up by other components).
– Werner
Dec 16, 2021 at 23:06
• Perfect, thanks a lot! Dec 17, 2021 at 4:33