Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize references to sublists in LaTeX?

Tags:

latex

pdflatex

I have a list/sublist structure in my LaTeX document. By default, the sublist is delimited with letters, so you end up with this:

1. Item
    (a) sub item
    (b) sub item

In my document, I've got more than 26 sub items, so I was running into a Counter overflow error, which I fixed by rewriting the sub item label, so that they now look like this

1. Item
    1.1 sub item
    1.2 sub item

I've put a label on one of the items so that I can reference the specific step later on. The problem is that when the reference is rendered, it's rendered using a letter, not the number of the sub item.

Here's a sample doc that shows the problem.

\documentclass[11pt]{report}

\begin{document}

\renewcommand{\labelenumii}{\arabic{enumi}.\arabic{enumii}}

\begin{enumerate}
    \item Item
    \begin{enumerate}
        \item \label{lbl} Label here
    \end{enumerate}
\end{enumerate}

Ref: \ref{lbl}

\end{document}

This gets rendered like this:

1. Item
    1.1 Label here
Ref: 1a

So instead of saying "Ref: 1.1", it's using "Ref: 1.a". Is there a way to make the \ref use the numbering of the source enumeration? If not, is there anyway to generate correct references to items in a sublist with more than 26 items?

like image 675
Matt McMinn Avatar asked Mar 27 '09 20:03

Matt McMinn


2 Answers

I'm looking at my copy of The LaTeX Companion, p.129, and from what I'm seeing I would suggest something like the following:

\renewcommand{\theenumii}{\arabic{enumii}}
\renewcommand{\labelenumii}{\theenumi.\theenumii.}
\makeatletter
\renewcommand{\p@enumii}{\theenumi.}
\makeatother

I don't have access to a working LaTeX environment to test this at the moment, though.

like image 105
David Z Avatar answered Nov 03 '22 10:11

David Z


So for 2 nested lists it should be done in the following way:

\begin{enumerate}
\renewcommand{\theenumi}{\arabic{enumi}}
\renewcommand{\theenumii}{\arabic{enumii}}
\renewcommand{\theenumiii}{\arabic{enumiii}}

\renewcommand{\labelenumi}{\theenumi.}
\renewcommand{\labelenumii}{\theenumi.\theenumii.}
\renewcommand{\labelenumiii}{\theenumi.\theenumii.\theenumiii.}

\makeatletter
\renewcommand{\p@enumii}{\theenumi.}
\renewcommand{\p@enumiii}{\theenumi.\theenumii.}
\makeatother

...

\end{enumerate}

It has taken to me too much time to understand it. I hope this helps as this thread helped me.

Thanks.

like image 39
Siempre Avatar answered Nov 03 '22 10:11

Siempre