Item counter within enumerate

#enumeratecounters

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

Best Answer

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}
Related Question