# restricting hyperref link to part of toc / lo* entry

In some tocloft list there are entries, which may span multiple lines. Now hyperref makes the number in front, the first line and all the following lines into links. Can this be prevented? Only the first line should be a link.
See the following example, where this happens:

\documentclass{scrartcl}

\usepackage{hyperref}

\usepackage{tocloft}
\newcommand{\listprname}{Problems}
\newlistof{pr}{pr}{\listprname}

\newcommand\pr[2]{%
\refstepcounter{pr}
{\protect\numberline{\thepr.}{#1\\#2}}}

\begin{document}

\listofpr

\pr{Test}{This is rather a description.}

\end{document}


I don't know of an option of the hyperref package that achieves your stated goal. However, you may want to consider specifying the linktocpage=true option, which will make the page numbers associated with the entries in the TOC, LoF, and LoT into hyperlink targets. Personally, I find the option to "color" just the page numbers, rather than all other parts of a given entry in these lists, quite appealing.

Based on Mico's answer and the other article, How to make a hyperlink cover the whole line in table of contents including the dots?, I figured it out:

\documentclass{scrartcl}

\usepackage{tocloft}
\newcommand{\listprname}{Problems}
\newlistof{pr}{pr}{\listprname}

\makeatletter
\newcommand\pr[2]{%
\refstepcounter{pr}
\makeatother

\begin{document}

\listofpr

\pr{Test}{This is rather a description.}

\end{document}


Of course this relies on the internal label naming scheme of hyperref. Also the number in front is not a link for now, but that can be added too.

Furthermore settings can be changed for each list separately by using \hypersetup{linktoc=page} before and \hypersetup{linktoc=all} after the list, the changes shall be applied to. This way no changes are necessary to keep the entries in the main toc as links.

As Heiko noted, it is not necessary to use the internal hyperref commands. The following code contains this adjustment and also puts the number in a link:

\addcontentsline{pr}{pr}%

• You get the number into the link by putting \numberlinewith its number argument in the link. Also there is no need for internal commands. Result: {\protect\hyperlink{pr.\thepr}{\protect\numberline{\thepr.}#1\\#2}} – Heiko Oberdiek Jul 29 '12 at 22:25
• It was just a typing error: {\protect\hyperlink{pr.\thepr}{\protect\numberline{\thepr.}#1}\\#2} (comments do not seem to allow properly formatted and indented code). – Heiko Oberdiek Jul 30 '12 at 9:45
• @HeikoOberdiek: That makes sense of course and I stick with seperate \hyperlinks only, because then it is a little bit easier to handle empty first/second line. – bodo Jul 30 '12 at 10:19