我想找到一个解决方案来生成像这样的反向计数的项目
- 啦啦啦
- 啦啦啦
- 啦啦啦
答案1
也许像这样的事情可以解决问题——它至少需要两次编译才能解决:
\documentclass{article}
\usepackage[colorlinks=true]{hyperref}
\usepackage[user]{zref}
\makeatletter
\zref@newprop{ItemNo}{}%
\newcommand\my@caseselect[2]{#2}%
\newcommand\ItemNumberlabel[1]{%
\bsphack
\begingroup
\let\my@caseselect=\@firstoftwo
\zref@setcurrent{ItemNo}{\number\value{enum\romannumeral\@enumdepth}}%
\zref@labelbyprops{#1}{ItemNo}%
\endgroup
\esphack
}%
\newcommand\revertcounting[2]{%
\expandafter\@revertcounting
\expandafter{\romannumeral\the\numexpr\@enumdepth+1\expandafter\relax\expandafter}%
\expandafter{\romannumeral\the\@enumdepth}%
{#1}{#2}%
\ignorespaces
}%
\newcommand\@revertcounting[4]{%
\@namedef{theenum#1}{%
\my@caseselect{%
\csname @#4\endcsname{\csname c@enum#1\endcsname}%
}{%
\zref@ifrefundefined{#3}%
{\csname @#4\endcsname{\csname c@enum#1\endcsname}}%
{%
\csname @#4\endcsname{%
\the\numexpr
\zref@extractdefault{#3}{ItemNo}{0} - %
\number\value{enum#1} + 1%
\relax
}%
}%
}%
}%
}%
\makeatother
\begin{document}
\null\par\kern-3cm
\begin{enumerate}
\item text A
\item text B
\item
\begin{enumerate}
\item text One
\item \label{itA}text Two
\item text Three
\item text Four
\end{enumerate}
\item text D
\end{enumerate}
\bigskip\hrule\bigskip
\begingroup
\revertcounting{lastitemA}{arabic}%
\begin{enumerate}
\item text A
\item text B
\item
\begingroup
\revertcounting{lastitemB}{alph}%
\begin{enumerate}
\item text One
\item \label{itB}text Two
\item text Three
\item \ItemNumberlabel{lastitemB}text Four
\end{enumerate}
\endgroup
\item \ItemNumberlabel{lastitemA}text D
\end{enumerate}
\endgroup
\bigskip\hrule\bigskip
\begingroup
\revertcounting{lastitemC}{arabic}%
\begin{enumerate}
\item text A
\item text B
\item
\begin{enumerate}
\item text One
\item \label{itC}text Two
\item text Three
\item text Four
\end{enumerate}
\item \ItemNumberlabel{lastitemC}text D
\end{enumerate}
\endgroup
\bigskip\hrule\bigskip
\begin{enumerate}
\item text A
\item text B
\item
\begingroup
\revertcounting{lastitemD}{alph}%
\begin{enumerate}
\item text One
\item \label{itD}text Two
\item text Three
\item \ItemNumberlabel{lastitemD}text Four
\end{enumerate}
\endgroup
\item text D
\end{enumerate}
Cross-referencing:
\verb|\ref{itA}|: \ref{itA}
\verb|\ref{itB}|: \ref{itB}
\verb|\ref{itC}|: \ref{itC}
\verb|\ref{itD}|: \ref{itD}
\end{document}