6

I'm using an enumeration with labels assigned to the items. Referencing to the items it works fine, but in some cases I would like to have "1st" or even "first" instead of just "1", with the former one not being that much of an issue, but as I'm also using hyperref I would like to have "1st" as a link and not only "1"st with the "1" being the link. But the "first" is more important for me and it should also be a clickable link. Does anyone have a solution for my issue?

see the MWE here:

\documentclass{article}
\usepackage[utf8]{inputec}
\usepackage[colorlinks=true]{hyperref}
\begin{document}
\begin{enumerate}
\item Item1 \label{itm:1}
\end{enumerate}
Item \ref{itm:1} xyz...\\
The \ref{itm:1}st item xyz...\\
The first item xyz...
\end{document}
6

You can use \hyperref to create a link like \ref would do (the first argument is an optional argument, but I don't know why):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[colorlinks=true]{hyperref}
\begin{document}
\begin{enumerate}
\item Item1 \label{itm:1}
\end{enumerate}
Item \ref{itm:1} xyz...\\
The \ref{itm:1}st item xyz...\\
The \hyperref[itm:1]{first} item xyz...
\end{document}
  • Works like a charm, thanks a lot! – Andreas Apr 25 at 7:23
7

Building on Ulrike’s answer,

\documentclass{article}
\usepackage{fmtcount}
\usepackage{refcount}
\usepackage[colorlinks=true]{hyperref}

\newcommand{\ordinalref}[1]{%
  \hyperref[#1]{\ordinalstringnum{\getrefnumber{#1}}}%
}

\begin{document}
\begin{enumerate}
\item Item1 \label{itm:1}
\end{enumerate}
Item \ref{itm:1} xyz...\\
The \ordinalref{itm:1} item xyz...\\
The first item xyz...
\end{document}

It doesn't work for nested items, unless you change the reference format.

enter image description here

  • Thanks, that also looks like a great solution and an even more flexible one than Ulrikes as it's more automated when adding/removing items. But is it possible to define the language for that to something different than english? – Andreas Apr 25 at 11:04
  • 1
    @Andreas fmtcount supports several languages, see its manual. – egreg Apr 25 at 11:21
  • Took some time, but now I've got it working like I want it to, with the german genders, thank you VERY much! – Andreas Apr 25 at 11:59
  • 2
    @UlrikeFischer True, but referring to an ordinal in the case of a nonnumeric reference would sound strange. – egreg Apr 25 at 13:18
  • 1
    In german writing "the first point" (der erste Punkt) for a point that is numbered as a) o i) would be quite natural - it would even work for an itemize. Also the code will also break if you add some formatting, e.g. 1) or Case 1. – Ulrike Fischer Apr 25 at 13:33

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.