枚举列表,标签如 1/3、2/3、3/3

枚举列表,标签如 1/3、2/3、3/3

我想要一个枚举列表,它 ① 支持resume并且 ② 使用符号n of N,例如(以 ASCII 格式)

1/4. Bla.
2/4. Bla bla.

Some additional bla bla,

3/4. from my balcone.
4/4. Bla bla.

想象我可以使用计数器,并可能使用两遍编译(但我不知道如何确切地执行此操作),但我想知道某些软件包是否已经提供了所请求的功能。

答案1

enumitem可以保存计数器的最终值。

\documentclass{article}
\usepackage{enumitem}

\newlist{gbenumerate}{enumerate}{1}
\setlist[gbenumerate]{
  wide,
  label=\arabic*/\gbenumall.,
}

\providecommand\gbenumall{0}% initial value

\makeatletter
\AtEndDocument{%
  \write\@auxout{\gdef\string\gbenumall{\the\value{gbenumeratei}}}%
}
\makeatother

\begin{document}

\begin{gbenumerate}
\item this is the first item
\item this is the second item
\end{gbenumerate}

Some text in between

\begin{gbenumerate}[resume]
\item this is the third item
\item this is the fourth item
\end{gbenumerate}

\end{document}

在此处输入图片描述

如果您想多次使用重置功能,则情况会稍微复杂一些gbenumerate。在这种情况下,您必须说明何时重置以及保存最后一个值。我建议将零件放在合适的环境中。

\documentclass{article}
\usepackage{enumitem}

\newlist{gbenumerate}{enumerate}{1}
\setlist[gbenumerate]{
  wide,
  label=\arabic*/\unexpanded{\gbenum{\thesubgbenumerate}}.,
  resume
}
\newcounter{subgbenumerate}

\makeatletter
\newenvironment{subgbenumerate}
 {%
  \stepcounter{subgbenumerate}%
 }
 {\immediate\write\@auxout{\string\storegbenum{\thesubgbenumerate}{\the\value{gbenumeratei}}}}
\newcommand{\storegbenum}[2]{%
  \expandafter\xdef\csname gbenum@#1\endcsname{#2}%
}
\newcommand{\gbenum}[1]{\ifcsname gbenum@#1\endcsname\csname gbenum@#1\endcsname\else 0\fi}
\makeatother

\AtEndDocument{%
}
\makeatother

\begin{document}

\begin{subgbenumerate}
\begin{gbenumerate}
\item this is the first item
\item this is the second item
\end{gbenumerate}

Some text in between

\begin{gbenumerate}
\item this is the third item
\item this is the fourth item
\end{gbenumerate}
\end{subgbenumerate}

Some text in between.

\begin{subgbenumerate}
\begin{gbenumerate}
\item this is the first item
\item this is the second item
\end{gbenumerate}

Some text in between

\begin{gbenumerate}
\item this is the third item
\item this is the fourth item
\item this is the fifth item
\end{gbenumerate}
\end{subgbenumerate}

\end{document}

在此处输入图片描述

相关内容