是否有一个标准包(或快速方法)来获取步骤/子步骤/...(最多三个级别)的枚举,其中有一个前导字母(或短字符串),并且可以引用枚举的每个项目?
例如:
S1. bla bla
S2. hello world
S2.1. aaaa
S2.2. bbbb
S2.2.1 cccc
S2.2.2 ddd
S3. as done in step S2.1 ... % \ref{some_label_at_S2.1)
...
R1. new enumeration with another letter
R1.1 zzzz
R1.2 wwww
R2. heeeelllllooooo
...
Step1. another enumeration with a short string
Step1.1. hello world
Step2.2. hello world
Step2. as said in \ref{some_label_at_R1)
...
答案1
我mylist
使用包构建了一个具有所需行为的环境enumitem
:它接受一个指定相应列表前缀的参数(在嵌套调用中不必再次提供此参数mylist
),并定义用于打印和引用的标签。使用\label
和可以按\ref
常规方式工作,无需额外努力。
\documentclass[a4paper]{article}
\usepackage{enumitem}
\usepackage{lipsum}
\newlist{mylistenv}{enumerate}{3}
\newenvironment{mylist}[1]{%
\setlist[mylistenv]{label=#1\arabic{mylistenvi}.,ref=#1\arabic{mylistenvi}}%
\setlist[mylistenv,2]{label=#1\arabic{mylistenvi}.\arabic{mylistenvii}.,ref=#1\arabic{mylistenvi}.\arabic{mylistenvii}}%
\setlist[mylistenv,3]{label=#1\arabic{mylistenvi}.\arabic{mylistenvii}.\arabic{mylistenviii}.,ref=#1\arabic{mylistenvi}.\arabic{mylistenvii}.\arabic{mylistenviii}}%
\renewenvironment{mylist}{\begin{mylistenv}}{\end{mylistenv}}
\begin{mylistenv}%
}{%
\end{mylistenv}%
}
\begin{document}
\begin{mylist}{S}
\item bla bla
\item hello world
\begin{mylist}
\item aaaa \label{some_label_at_S2.1}
\item bbbb
\begin{mylist}
\item cccc
\item ddd
\end{mylist}
\end{mylist}
\item as done in step~\ref{some_label_at_S2.1}
\end{mylist}
\lipsum[2]
\begin{mylist}{R}
\item new enumeration with another letter \label{some_label_at_R1}
\begin{mylist}
\item zzzz
\item wwww
\end{mylist}
\item heeeelllllooooo
\end{mylist}
\lipsum[4]
\begin{mylist}{Step}
\item another enumeration with a short string
\begin{mylist}
\item hello world
\item hello world
\end{mylist}
\item as said in \ref{some_label_at_R1}
\end{mylist}
\end{document}
答案2
您可以执行以下操作
\newcounter{ci}
\begin{list}{S.\arabic{ci}}{\usecounter{ci}}
\renewcommand{\theci}{S.\arabic{ci}}
\item\label{lbl1} Woof woof.
\newcounter{cii}
\begin{list}{S.\arabic{ci}.\arabic{cii}}{\usecounter{cii}}
\renewcommand{\thecii}{S.\arabic{ci}.\arabic{cii}}
\item\label{lbl11} Mew mew.
\newcounter{ciii}
\begin{list}{S.\arabic{ci}.\arabic{cii}.\arabic{ciii}}{\usecounter{ciii}}
\renewcommand{\theciii}{S.\arabic{ci}.\arabic{cii}.\arabic{ciii}}
\item Baa baa
\item\label{lbl112} Moo moo.
\end{list}
\item Tweet tweet.
\end{list}
\item Cluck cluck.
\end{list}
Woof ref: \ref{lbl1} \\
Mew ref: \ref{lbl11} \\
Moo ref: \ref{lbl112} \\
\end{document}
下面的也可以工作,除了看起来像是第三级枚举项的引用中的一个错误:
\documentclass{article}
\begin{document}
\begin{enumerate}
\renewcommand{\theenumi}{S.\arabic{enumi}}
\renewcommand{\labelenumi}{S.\arabic{enumi}}
\renewcommand{\theenumii}{.\arabic{enumii}}
\renewcommand{\labelenumii}{S.\arabic{enumi}.\arabic{enumii}}
\renewcommand{\theenumiii}{.\arabic{enumiii}}
\renewcommand{\labelenumiii}{S.\arabic{enumi}.\arabic{enumii}.\arabic{enumiii}}
\item bla bla
\item hello world
\begin{enumerate}
\item\label{athing} aaaa
\item bbbb
\begin{enumerate}
\item cccc
\item\label{thingy2} ddd
\end{enumerate}
\end{enumerate}
\item as done in step \ref{athing}
\item in contrast to step \ref{thingy2}
\end{enumerate}
\begin{enumerate}
\renewcommand{\theenumi}{R.\arabic{enumi}}
\renewcommand{\labelenumi}{R.\arabic{enumi}}
\renewcommand{\theenumii}{.\arabic{enumii}}
\renewcommand{\labelenumii}{R.\arabic{enumi}.\arabic{enumii}}
\renewcommand{\theenumiii}{.\arabic{enumiii}}
\renewcommand{\labelenumiii}{R.\arabic{enumi}.\arabic{enumii}.\arabic{enumiii}}
\item\label{newenum} new enumeration with another letter
\begin{enumerate}
\item zzzz
\item wwww
\end{enumerate}
\item heeeelllllooooo
\item ...
\end{enumerate}
\begin{enumerate}
\renewcommand{\labelenumi}{Step.\arabic{enumi}}
\renewcommand{\labelenumii}{Step.\arabic{enumi}.\arabic{enumii}}
\renewcommand{\labelenumiii}{Step.\arabic{enumi}.\arabic{enumii}.\arabic{enumiii}}
\item another enumeration with a short string
\begin{enumerate}
\item hello world
\item hello world
\end{enumerate}
\item as said in \ref{newenum}
\item an alternative to \ref{athing}
\end{enumerate}