2

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:

enter image description here

\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

3
  • Erh did you read the enumitem manual? label=Ex. \arabic* seems to do what you want
    – daleif
    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.
    – Darvid
    Dec 16, 2021 at 22:55
  • 1
    That is not clear from your question, please rephrase
    – daleif
    Dec 16, 2021 at 22:57

1 Answer 1

2

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

enter image description here

\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.

enter image description here

\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}
3
  • 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.
    – Darvid
    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!
    – Darvid
    Dec 17, 2021 at 4:33

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.