5

If I try to label items in a list as in

\documentclass{article}

\usepackage{hyperref}

\begin{document}

\begin{itemize}
\item blah \label{list:blah}

\pagebreak

\item foo \label{list:foo}

\pagebreak
\end{itemize}

reference to blah \ref{list:blah}
\pagebreak
reference to foo \ref{list:foo}

\end{document}

Then the links back to the items all go back to the beginning of the list. Is there a way to make each list item be separately labelled?

lockstep
  • 250,273
Peeter Joot
  • 3,025
  • 2
  • 25
  • 35
  • What do the \refs expand to? – Joseph R. Nov 08 '12 at 15:49
  • \newlabel{list:blah}{{}{1}{\relax }{Doc-Start}{}} \newlabel{list:foo}{{}{2}{\relax }{Doc-Start}{}} – Peeter Joot Nov 08 '12 at 15:54
  • I meant what do they appear like in the final document. – Joseph R. Nov 08 '12 at 16:00
  • Answers to following question might be of help to create itemize lists with labels: http://tex.stackexchange.com/questions/74595/count-and-use-the-number-of-items-in-advance – mythealias Nov 08 '12 at 16:03
  • I edited the title, because the question wasn't really about whether you can label and reference individual list items, it is about getting the hyperref anchors to point to the right place. – Seamus Nov 08 '12 at 16:15

2 Answers2

8

It's uncommon to try to link to items within an itemize environment as they are unnumbered, and do not define anchors. There is no natural text to associate either.

By adding \phantomsection to every \item, you can provide anchors. There will still be no associated text, and hyperref will still complain of an empty link. Instead, you may use your own link text and the \hyperref command instead of \ref:

\documentclass{article}

\usepackage{hyperref}

\usepackage{etoolbox}
\AtBeginEnvironment{itemize}{\apptocmd{\item}{\phantomsection}{}{\errmessage{couldn't patch item}}}
\begin{document}

\begin{itemize}
\item blah \label{list:blah}

\pagebreak

\item foo \label{list:foo}

\pagebreak
\end{itemize}

reference to blah \hyperref[list:blah]{blah}
\pagebreak
reference to foo \hyperref[list:foo]{foo}

\end{document}
6

I don't think the links will work with itemize as you don't have a unique number to point to. An error is generated like

Package hyperref Warning: Suppressing empty link on input line 17.


Package hyperref Warning: Suppressing empty link on input line 19.

Try it with enumerate and it works:

\documentclass{article}

\usepackage[colorlinks]{hyperref}

\begin{document}

\begin{enumerate}

\item blah \label{list:blah}

\pagebreak

\item foo \label{list:foo}

\pagebreak
\end{enumerate}

reference to blah \ref{list:blah}
\pagebreak
reference to foo \ref{list:foo}

\end{document}

If you want this to work with itemize you may use \pageref. But I am not sure to what extent this will be helpful in this case.

\documentclass{article}

\usepackage[colorlinks]{hyperref}

\begin{document}

\begin{itemize}

\item blah \label{list:blah}

\pagebreak

\item foo \label{list:foo}

\pagebreak
\end{itemize}

reference to blah \pageref{list:blah}
\pagebreak
reference to foo \pageref{list:foo}

\end{document}