2

Is there a standard package (or a quick way) to get an enumeration of steps/substesp/... (up to three levels) with a leading letter (or short string) and the possibility of reference each item of the enumeration?

For example:

 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)

...

  • 2
    enumitem is a powerful package – user31729 Jan 29 '18 at 8:27
1

I built an environment mylist with the desired behaviour using the enumitem package: It takes an argument specifying the prefix of the respective list (this argument doesn't have to be provided again in nested calls of mylist) and defines the label both for printing and referencing accordingly. Using \label and \ref works the usual way without any extra effort.

\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}

enter image description here

  • G.r.e.a.t.!!!!! Exactly what I wanted without too many efforts – Marzio De Biasi Jan 29 '18 at 10:54
1

You could do the following

\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}

The following would also work, except for what looks like a bug in the referencing of 3rd level enumerate items:

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.