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.

I have redefined the enumerate counters to include the section number, and this works as expected. However, when I try to cross-reference text in my document, the number on the reference doesn't show correctly.

Update:
Upon request, I have edited in a full MWE here instead of the original sample code.

\documentclass{article}

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

\begin{document}

\section{The main stuff}
\begin{enumerate}
    \item Some text
    \item \textbf{A header}
    \begin{enumerate}
        \item The first item in a sublist
        \item \label{important} This stuff is really cool
        \begin{enumerate}
            \item Some text here...
            \item ...and here
        \end{enumerate}
    \end{enumerate}
    \item The outer list continues
\end{enumerate}

When I reference \lq\lq{}important\rq\rq{}, I get \ref{important}

\end{document}

The last row outputs

When I reference "important", I get 1.21.2.2

where I would have expected the number to be just simply 1.2.2.

Solution:
The solution to this problem was presented by Geoffrey Jones - simply switching from one suggested way of changing the numbering to the other made it work. Instead of the above \newcommands, the following works:

\usepackage{enumitem}
\setenumerate[1]{label=\thesection.\arabic*.}
\setenumerate[2]{label*=\arabic*.}
\setenumerate[3]{label*=\arabic*.}
share|improve this question
3  
Tomas, you haven't provided sufficient information. It would be better if (in all code-related questions) you could provide a minimum working example. However, to work with the supplied code, can you please explain or, better yet, provide your definitions for \punkt and in particular \The in the code you have provided above (unless these are typos, in which case can you please edit them into shape before we launch into this)? –  Geoffrey Jones Sep 27 '10 at 13:18
    
@Geoffrey - sorry, those were both typos. They have been corrected (to \item The and \item respectively). –  Tomas Lycken Sep 27 '10 at 13:34
    
That behaviour is very odd. Your code is what I would first try when attempting something like this. I wonder where/how in the 2e sources this problem comes from. Lucky that enumitem fixes thing :) –  Will Robertson Sep 28 '10 at 15:19
    
@Will, yes, I scratched my head about this for a while. Then the lightbulb went on ... Tomas's output is exactly what LaTeX should produce. See my second answer, below, for what I mean. :) –  Geoffrey Jones Sep 29 '10 at 2:05
    
+1 for the fix-up :) –  Geoffrey Jones Sep 29 '10 at 2:10
add comment

2 Answers

up vote 4 down vote accepted

Tomas, I've tried my best to replicate your problem but no matter what I do, I can't get anything to go wrong at all. In the absence of your providing a MWE (which, frankly, I wish you could have supplied), I'm guessing that your code looks essentially like this:

\documentclass{article}
\usepackage{verbatim}     % this is just for the print-out below
\usepackage{enumitem}     % for lack of a MWE, I'm just guessing here
\setenumerate[1]{label=\thesection.\arabic*.}
\setenumerate[2]{label*=\arabic*.}
\setenumerate[3]{label*=\arabic*.}

\begin{document}
\setcounter{section}{3}   % to remain in sync with your numbering
\section{The main stuff}
  \begin{enumerate}
    \item Some text
    \item \textbf{A header}
    \begin{enumerate}     % NB, your code had \begin{item} here which, judging by 
                          % your printout, I assume to be another typo (correct me
                          % if I'm wrong
      \item The first item in a sublist
      \item \label{important} This stuff is really cool
      \begin{enumerate}   % NB, ditto
          \item Some text here...
          \item ...and here
      \end{enumerate}
    \end{enumerate}
  \end{enumerate}
  ``When I reference this label (\verb|\ref{important}|), 
  the number that shows up is \ref{important}''
\end{document}

Apart from the listing part of my printout coinciding with your listing in your question, my code includes the following line:

"When I reference this label (\ref{important}), the number that shows up is 4.2.2."

So obviously our code does not coincide. Can you help me out by providing a MWE that doesn't leaving people guessing about what's causing the problem you see?

share|improve this answer
    
Sorry - I should have mentioned that I used the first solution in his answer (redefining the \theenumi commands). When I change it to the second solution, it works as your code. However, this seemingly doesn't allow for the same depth of nesting without loosing the number format. Is there any way to fix that? –  Tomas Lycken Sep 27 '10 at 21:54
11  
@Tomas. Honestly, patience has its limits. You can't expect people to help you with your problems if you persist in making things difficult for them. I have asked (quite nicely) for a compilable MWE for this question at least 3 times now, having wasted my time guessing what you want, yet with complete disregard for that you wave a few words around then ask "Is there any way to fix that?" I suggest that if you want to be a well-respected member of this community (and of course everyone wants you to be), then at least try to show everyone an appropriate level of care. Seriously, man. Sigh. –  Geoffrey Jones Sep 28 '10 at 0:35
add comment

Tomas, excellent update. Now we can see what's going on.

As odd as the result you see is at first glance, it happens that your odd output is exactly what LaTeX should produce without further modifications from you. Here's a modified version of your (new) code to help you see what's going on (sorry for the long lines):

\documentclass{article}
\usepackage{verbatim}
\usepackage[margin=1in]{geometry}

%\renewcommand*{\theenumi}{\thesection.\arabic{enumi}}  % run once without uncommenting, review output, then uncomment and run again
%\renewcommand*{\theenumii}{\theenumi.\arabic{enumii}}  % uncomment after running and reviewing ouput from uncommented line above

\begin{document}
\section{Stuff}
  \begin{enumerate}
    \item This line contains \verb|\label{a}|. \label{a} \verb|\labelenumi|: \labelenumi;\ \verb|\theenumi|: \theenumi
    \item This line contains \verb|\label{b}|. \label{b} \verb|\labelenumi|: \labelenumi;\ \verb|\theenumi|: \theenumi
    \begin{enumerate}
      \item This line contains \verb|\label{c}|. \label{c} \verb|\labelenumii|: \labelenumii;\ \verb|\theenumii|: \theenumii
      \item This line contains \verb|\label{d}|. \label{d} \verb|\labelenumii|: \labelenumii;\ \verb|\theenumii|: \theenumii
      \begin{enumerate}
        \item This line contains \verb|\label{e}|. \label{e} \verb|\labelenumiii|: \labelenumiii;\ \verb|\theenumiii|: \theenumiii
        \item This line contains \verb|\label{f}|. \label{f} \verb|\labelenumiii|: \labelenumiii;\ \verb|\theenumiii|: \theenumiii
      \end{enumerate}
    \end{enumerate}
  \end{enumerate}
  \verb|\ref|'s to \verb|\label|'s\{a, b, c, d, e, f\}: \ref{a}, \ref{b}, \ref{c}, \ref{d}, \ref{e}, \ref{f}.
\end{document}

As you can see if you run this code as is, the output LaTeX produces is:

\ref's to \label's{a, b, c, d, e, f}: 1, 2, 2a, 2b, 2(b)i, 2(b)ii.

I hope you'll agree that that is the result everyone would ordinarily expect LaTeX to produce.

Now, if you uncomment the first of your \renewcommand's, your output will include:

\ref's to \label's{a, b, c, d, e, f}: 1.1, 1.2, 1.2a, 1.2b, 1.2(b)i, 1.2(b)ii.

OK, so now it's starting to look a little strange. But it follows from what we just saw before (right?).

Finally, if you uncomment the second of your \renewcommand's, you'll see:

\ref's to \label's{a, b, c, d, e, f}: 1.1, 1.2, 1.21.2.1, 1.21.2.2, 1.2(1.2.2)i, 1.2(1.2.2)ii.

which, while exactly as you describe in your problem statement, nevertheless follows consistently from the results we saw in our previous tests above.

So now you can see what's going on (and that your expectations about the output you saw didn't account for the way LaTeX prints labels in enumerate environments).

To fix this (which I wouldn't bother with given the working solution I provided above), you're going to need to dive into redefining LaTeX's \p@enumii and \p@enumiii, but that's a whole new kettle of fish.

share|improve this answer
    
Great analysis, thanks. –  Will Robertson Sep 29 '10 at 2:05
1  
More details in this FAQ answer, which explains the \p@enumii stuff but ultimately recommends enumitem. –  Lev Bishop Sep 29 '10 at 20:49
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.