4

If I define numberenum like following,

\newenvironment{numberenum}
{\renewcommand{\labelenumi}{(\arabic{enumi})}
\renewcommand{\labelenumii}{(\arabic{enumi}.\arabic{enumii})}
\renewcommand{\labelenumiii}{(\arabic{enumi}.\arabic{enumii}.\arabic{enumiii})} 
\begin{enumerate}}
{\end{enumerate}}

\begin{numberenum}
    \item depth 1
    \begin{enumerate}
        \item depth 2
        \begin{enumerate}
            \item depth 3
        \end{enumerate}
    \end{enumerate}
\end{numberenum}

result of code 1

Then I can get the above result. However, after depth 4, this code doesn't work. It's easy to redefine \labelenumiv, but the point is generating the label keeping this pattern until the depth limit of enumerate list.

custom labels for enumerate beyond level 4

This article solved a similar problem using label* method. But my case is more tricky because of brackets. Is there any way to define numberenum properly?

8

EDIT: Ahem. I just realised that there is a way simpler method to accomplish the same thing...

The enumitem package has a format key, which is normally used to set the font of the items labels (the font key is an alias for it). The formatted label will look like <format>{<label>}, where <format> is the value of the format key and <label> is the value of the label key.

You can define a macro that wraps its argument in parentheses and use that for the format key, like this: (I made the labels bold to show that this is still possible, but you can't swap \bfseries and \parenthesize.)

\documentclass{article}

\usepackage{enumitem}

\renewlist{enumerate}{enumerate}{10} %% <- set the max depth to 10
\newcommand*\parenthesize[1]{(#1)}
\setlist[enumerate]{label*=.\arabic*,format=\bfseries\parenthesize,leftmargin=2em}
\setlist[enumerate,1]{label=\arabic*} %% <- set the base level label separately

\begin{document}

\begin{enumerate}
  \item this is level 1
    \item this is still level 1
    \begin{enumerate}
      \item this is level 2
      \item this is still level 2
        \begin{enumerate}
          \item this is level 3
          \item this is still level 3
            \begin{enumerate}
              \item this is level 4
              \item this is still level 4
                \begin{enumerate}
                  \item this is level 5 \label{deepitem}
                  \item this is still level 5
                \end{enumerate}
            \end{enumerate}
        \end{enumerate}
    \end{enumerate}
\end{enumerate}

This is a reference to second-to-last item: \ref{deepitem}.

\end{document}

enter image description here

| improve this answer | |

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.