3

I am using the enumitem package and need to access the counter values after the end of the environment. With a standard

\newlist{Example}{enumerate}{2}

for instance, the counter value is simply the list name with an i appended to the end: Examplei.

What is the counter name when an inline list is declared, such as

\newlist{Example*}{enumerate*}{2}%

The value highlighted in red is incorrect and should be 2:

enter image description here

Notes:

  • Ideally, I would prefer to have the inline version use the same counter as the non-inline version. But a solution just accessing the inline counter might be useful for others who come across this question.

Code:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}

\newlist{Example}{enumerate}{2}%
\setlist[Example]{label={\arabic*.}}

\newlist{Example*}{enumerate*}{2}%
\setlist[Example*]{itemjoin={\hspace*{2.0em}}, label={\arabic*.}}


\begin{document}
\textbf{Vertical List}
\begin{Example}
    \item First V item.
    \item Second V item.
    \item Third V item.
\end{Example}

There were \arabic{Examplei} elements in prior list.

\bigskip
\textbf{Horizontal List}:
\begin{Example*}
    \item First H item.
    \item Second H item.
\end{Example*}

\medskip
%% How do I get the correct count here?
There were \textcolor{red}{\arabic{Examplei}} elements in prior list.

\end{document}

1 Answer 1

2

It's Example*i:

enter image description here

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}

\newlist{Example}{enumerate}{2}%
\setlist[Example]{label={\arabic*.}}

\newlist{Example*}{enumerate*}{2}%
\setlist[Example*]{itemjoin={\hspace*{2.0em}}, label={\arabic*.}}


\begin{document}
\textbf{Vertical List}
\begin{Example}
    \item First V item.
    \item Second V item.
    \item Third V item.
\end{Example}

There were \arabic{Examplei} elements in prior list.

\bigskip
\textbf{Horizontal List}:
\begin{Example*}
    \item First H item.
    \item Second H item.
\end{Example*}

\medskip
%% How do I get the correct count here?
There were \textcolor{red}{\arabic{Example*i}} elements in prior list.

\end{document}

If you wish for the inline enumeration Example* to use the same counter as Example, you can add

\makeatletter
\expandafter\let\csname c@Example*i\endcsname\c@Examplei
\makeatother

to your preamble after defining both lists.

2
  • What if we didn't use newlist and used enumerate* directly? What would the counter name be? Jul 23, 2021 at 20:25
  • @RaffiKhatchadourian: The counter used within enumerate* (when you load \usepackage[inline]{enumitem} is enumi (see the value when you print \theenumi).
    – Werner
    Jul 25, 2021 at 1:26

You must log in to answer this question.

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