Include section number in list number

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...

-

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.

-
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. – José Figueroa-O'Farrill Aug 5 '10 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? – Tomas Lycken Aug 5 '10 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. – Tomas Lycken Aug 5 '10 at 13:00
The parentheses can be removed by \renewcommand{\labelenumii}{\theenumii}. – Stefan Kottwitz Aug 5 '10 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 Aug 5 '10 at 13:07

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

-
Yep, I just checked and it works. – José Figueroa-O'Farrill Aug 5 '10 at 12:33
I was half-way though typing up the same thing when your answer and Stefan's appeared! – Joseph Wright Aug 5 '10 at 12:36

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.

-