23

As a follow-up to this question, I'd like to know if it is possible to automatically include the current section number, including all nesting levels, in the list number. How do I accomplish this?

Example of what I want:

\section{This is section 1}
  \pointedenum\begin{enumerate}
    \item This item has number 1.1.
    \item This item has number 1.2.
    \pointedenum\begin{enumerate}
      \item This item has number 1.2.1.
    \end{enumerate}
  \end{enumerate}

  \subsection{This is section 1.1}
    \pointedenum\begin{enumerate}
      \item This item has number 1.1.1.
      \item This item has number 1.1.2.
    \end{enumerate}
% etcetera...

3 Answers 3

32

You could redefine \theenumi using \thesection:

\renewcommand*{\theenumi}{\thesection.\arabic{enumi}}
\renewcommand*{\theenumii}{\theenumi.\arabic{enumii}}

In that case omit \pointedenum, it would destroy that redefinition.

That may also be done using \thesubsection.

Alternatively, here's code using the enumitem package:

\usepackage{enumitem}
\setenumerate[1]{label=\thesection.\arabic*.}
\setenumerate[2]{label*=\arabic*.}

Using enumitem you're able to continue numbering by \begin{enumerate}[resume] if you like.

10
  • Yes, this is a better answer than mine, because it does not require doing this at every level. I had not read the previous question. Commented Aug 5, 2010 at 12:39
  • Nice - and fast! =) When I do this, I get the number on the first nesting level wrapped in parenthesis, that is, item number 1.1.2 in the example list looks like "(1.1.2.) This is item number 1.1.2.". Is this caused by this approach, or something else? Commented Aug 5, 2010 at 12:54
  • Also, this doesn't seem to allow me to nest sections and enumerations at will. I'd like to be able to use sections in the middle of enumerations, and the numbering would stay consistent across all different elements. I'm only going to have one huge list (as far as the numbers are concerned) in the entire document, so I don't really care if this messes up lists that are next to each other. Commented Aug 5, 2010 at 13:00
  • 2
    The parentheses can be removed by \renewcommand{\labelenumii}{\theenumii}.
    – Stefan Kottwitz
    Commented Aug 5, 2010 at 13:01
  • If you want to resume enumaration after \section, use enumitem and the resume option. I will add enumitem code above.
    – Stefan Kottwitz
    Commented Aug 5, 2010 at 13:07
5

The variables governing the labels for the items in an enumerated list are \labelenumi (for the top level), \labelenumii (next-to-top level),... You can use \renewcommand to redefine them to anything you want.

I would expect this to work, but I have not tried it:

\renewcommand{\labelenumi}{\thesection.\arabic{enumi}}
\renewcommand{\labelenumii}{\thesection.\arabic{enumi}.\arabic{enumii}}
2
  • Yep, I just checked and it works. Commented Aug 5, 2010 at 12:33
  • I was half-way though typing up the same thing when your answer and Stefan's appeared!
    – Joseph Wright
    Commented Aug 5, 2010 at 12:36
3

I usually resolve this with the enumerate package. I always use this package anyway to control how items are enumerated by allowing you to specify e.g. \begin{enumerate}[(1)] to have parentheses the numbers etc.. In preamble use

\usepackage{enumerate}

Then:

\section{This is section 1}
\begin{enumerate}[\thesection .1]
\item This is item 1.1
\item This is item 1.2
\end{enumerate}

\subsection{This is section 1.1}
\begin{enumerate}[\thesubsection .1]
\item This is item 1.1.1
\item This is item 1.1.2
\end{enumerate}

This solution allows you to use section numbering in enumerate only where you specify it. However if you want to do this globally I would use Stefan Kottwitz' solution above.

1
  • Thank you! Wonderful :)
    – Julia L.
    Commented Mar 25, 2020 at 9:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .