Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
    \addcontentsline{pr}{pr}%
    {\protect\numberline{\thepr.}{#1\\#2}}}

\begin{document}

    \listofpr

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

\end{document}
share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment
up vote 4 down vote accepted

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[linktocpage=true]{hyperref}

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

\makeatletter
\newcommand\pr[2]{%
    \refstepcounter{pr}
    \addcontentsline{pr}{pr}%
    {\protect\numberline{\thepr.}{\protect\hyper@linkstart{link}{pr.\thepr}#1\protect\hyper@linkend\\#2}}}
\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}%
{\protect\numberline{\protect\hyperlink{pr.\thepr}{\thepr.}}%
    {\protect\hyperlink{pr.\thepr}{#1}\\#2}}%
share|improve this answer
    
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
    
@HeikoOberdiek: If you do that, you are missing the point of the question: only the first line should be in the hyperlink. But nevertheless you are correct about the use of internal commands. I will add that to the answer. Thank you. –  canaaerus Jul 30 '12 at 5:37
    
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. –  canaaerus Jul 30 '12 at 10:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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