1

I want my references to nested items in an enumerated list to include all the punctuation that was in the list. Here is a simple example:

\documentclass{article}
\begin{document}
\begin{enumerate}
    \item whatever
    \item 1st level \label{first}
        \begin{enumerate}
            \item whatever
            \item 2nd level \label{second}
                \begin{enumerate}
                    \item whatever
                    \item 3rd \label{third} 
                        \begin{enumerate}
                            \item whatever
                            \item 4th \label{fourth}
                        \end{enumerate}
                \end{enumerate}
        \end{enumerate}
\end{enumerate}

1st: \ref{first}

2nd: \ref{second}

3rd: \ref{third}

4th: \ref{fourth}

\end{document}

This is the output I get (I'm showing it as code because the quotes don't preserve spaces at the start of the line)

1. whatever  
2. 1st level  

    (a) whatever 

    (b) 2nd level  

        i. whatever  

       ii. 3rd  

            A. whatever  

            B. 4th

1st: 2  
2nd: 2b  
3rd: 2(b)ii  
4th: 2(b)iiB

The problem is the missing punctuation in the four references at the end. I want the references at the end to look like this:

1st: 2.
2nd: 2.(b)
3rd: 2.(b).ii.
4th: 2.(b).ii.B.

Although admittedly ugly, someone is demanding the references look exactly like they do in the list.

I would prefer to do this without any \usepackage stuff that's not standard in most latex installations. So, I want to redefine the way the \ref works and have it leave all the punctuation in place, or redefine whatever will make it do what I want, without including any outside package.

2
  • Welcome to TeX.SE. Should there be a dot between "(b)" and "ii" in the third cross-reference?
    – Mico
    Commented May 8, 2015 at 1:20
  • Ooops, didn't want that dot between "(b)" and "ii". Commented May 8, 2015 at 2:59

1 Answer 1

3

Without any packages as wanted by OP.

\documentclass{article}
\renewcommand{\theenumi}{\arabic{enumi}.}
\renewcommand{\labelenumi}{\theenumi}
\renewcommand{\theenumii}{(\alph{enumii})}
\renewcommand{\labelenumii}{\theenumii}
\renewcommand{\theenumiii}{\roman{enumiii}.}
\renewcommand{\labelenumiii}{\theenumiii}
\renewcommand{\theenumiv}{\Alph{enumiv}.}
\renewcommand{\labelenumiv}{\theenumiv}
\makeatletter
\renewcommand\p@enumii{\theenumi}
\renewcommand\p@enumiii{\theenumi\theenumii.}  %% if you don't want that dot between "(b)" and "ii" remove the . at the end after \theenumii
\makeatother
\begin{document}
\begin{enumerate}
    \item whatever
    \item 1st level \label{first}
        \begin{enumerate}
            \item whatever
            \item 2nd level \label{second}
                \begin{enumerate}
                    \item whatever
                    \item 3rd \label{third}
                        \begin{enumerate}
                            \item whatever
                            \item 4th \label{fourth}
                        \end{enumerate}
                \end{enumerate}
        \end{enumerate}
\end{enumerate}

1st: \ref{first}

2nd: \ref{second}

3rd: \ref{third}

4th: \ref{fourth}

\end{document}

enter image description here

4
  • Thank you. That works. I removed the extra dot. Thanks for making it easy with the comment. Commented May 8, 2015 at 3:02
  • Ciao Harish. How are you? Commented May 8, 2015 at 5:32
  • @karlkoeller Hi Karl! I am fine but missing you a lot! :-)
    – user11232
    Commented May 8, 2015 at 9:21
  • This works great, but is there a way to do this using extra packages? I like to keep my preamble clean.
    – NWMT
    Commented Jan 11, 2018 at 15:53

You must log in to answer this question.

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