Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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...
share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

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.

share|improve this answer
    
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
2  
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
show 3 more comments

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}}
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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