1

I have the following problem : I have a counter (in my case enumi) that I want to use for referencing with a different name than when it is appears first. Is there a tool in Tex/Latex to do this?

To be more precise : I want to write this in my document body:

\section{Lorem}
\subsection{Ipsum}

\begin{enumerate}
\item \label{my_item} dolor sit amet
\item consectetur
\end{enumerate}

and have the list appear as:

i) dolor sit amet

ii) consectetur

but when using \ref{my_item} getting 1.1.i (assuming "Ipsum" is subsection 1.1). So using :

\renewcommand{\theenumi} {\bf \arabic{section}.\arabic{subsection}.\roman{enumi}~}

is not what I want.

1 Answer 1

3

Your formatting objective may be achieved without loading any extra LaTeX packages (though there is, of course, nothing wrong with loading suitable packages). Just add the following code to the preamble:

\renewcommand\labelenumi{\roman{enumi})} % determine look of label
\renewcommand\theenumi\labelenumi
\makeatletter
\renewcommand\p@enumi{\thesubsection.} % "prefix" for cross-references
\makeatother

A full MWE:

enter image description here

\documentclass{article} 
\renewcommand\labelenumi{\roman{enumi})}
\renewcommand\theenumi\labelenumi
\makeatletter
\renewcommand\p@enumi{\thesubsection.}
\makeatother
\begin{document} 

\section{Lorem}
\subsection{Ipsum}

\begin{enumerate}
\item \label{my_item} dolor sit amet
\item consectetur
\end{enumerate}

\section{Dolor}

A cross-reference to item \ref{my_item}.
\end{document}

Addendum: The same output may be achieved by loading the enumitem package as follows:

\usepackage{enumitem}
\setlist[enumerate,1]{label*=\roman*),
                      ref=\thesubsection.\roman*)}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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