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.

I am using KOMA-Script (scrreprt) and hyperref.

The PDF bookmarks are generated nicely from the table of contents, but I would like an extra Contents bookmark to point to the table of contents itself (without including an entry in the table of contents) - like the KOMA manual itself.

(Also list of figures and list of tables if I include them)

What is the best way to do this?

I could add a \pdfbookmark manually but I'm not sure how to get it to point correctly to the start of the section - if I do it after it will be on the wrong page (multipage toc), if I do before it will be the page before (since \tableofcontents does \cleardoublepage?). I guess I have to redefine \tableofcontents somehow.

share|improve this question
add comment

3 Answers

up vote 10 down vote accepted

The following code should create a correct ToC bookmark for both scrreprt and scrbook:

\makeatletter
\usepackage{etoolbox}
\pretocmd{\tableofcontents}{%
  \if@openright\cleardoublepage\else\clearpage\fi
  \pdfbookmark[0]{\contentsname}{toc}%
}{}{}%
\makeatother
share|improve this answer
    
Perfect, thanks... –  thrope Aug 16 '10 at 11:28
1  
For the lists of figures and tables, the above code should work by replacing \tableofcontents with \listoffigures resp. \listoftables, \contentsname with \listfigurename resp. \listtablename, toc with lof resp. lot. –  lockstep Aug 16 '10 at 11:28
add comment

A general way for base classes using \addtocontents would be:

\addtocontents{toc}{\protect{\pdfbookmark[0]{\contentsname}{toc}}}

Similar for lof and lot with \listfigurename and \listtablename.

But, since KOMA-Script uses tocbasic, this would be better way and very simple:

\BeforeTOCHead[toc]{{\pdfbookmark[0]{\contentsname}{toc}}}

Just this line will get you the bookmark for the table of contents.

Here's a compilable example, where \BeforeTOCHead is used to create bookmarks for all such lists like toc, lof and lot.

\documentclass{scrbook}
\usepackage{hyperref}
\makeatletter
\BeforeTOCHead{%
  \cleardoublepage
    \edef\@tempa{%
      \noexpand\pdfbookmark[0]{\list@fname}{\@currext}%
    }\@tempa
}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\chapter{One}
text
\end{document}

No redefinition of \tableofcontents and no etoolbox would be required. Different names by babel are supported.

share|improve this answer
    
I tried \BeforeTOCHead[toc]{{\pdfbookmark[0]{\contentsname}{toc}}} but the bookmark seems to link to the blank left hand page before to toc (which starts on right hand side) –  thrope Aug 16 '10 at 12:48
1  
Oh never mind \BeforeTOCHead[toc]{{\cleardoublepage\pdfbookmark[0]{\contentsname}{toc}}} seems to do it. Thanks very much –  thrope Aug 16 '10 at 12:50
    
Hmm, the code for all bookmarks doesn't work with the listings package, it points to the right page but the bookmark's name is empty. –  neo Jan 6 '13 at 17:44
1  
@Anton: Did you load babel, as in e.g. \usepackage[ngerman]{babel}? –  dapperdan Dec 17 '13 at 22:10
1  
@Anton: Sorry, then I guess you will have to post a new question with a MWE, because I cannot reproduce your problem with Stefan's example. Let us know here if you do, please. You might also want to check the order of your commands in the preamble, i.e. load babel early, though I doubt that this is the cause of your problem. –  dapperdan Dec 18 '13 at 21:28
show 2 more comments

With KOMA scrreprt here are documentclass options for adding bibliography and the 'list of's to the table of contents:

\documentclass[
    a4paper,
    bibliography=totoc,
    listof=totoc,
    final
]{scrreprt} 

If you want to just add a pdf bookmark, you can use the command \pdfbookmark:

\pdfbookmark{\contentsname}{toc}
\tableofcontents
share|improve this answer
1  
Although I prefer this solution to the other given answers, because it makes use of KOMA-options, the bookmark might point the end of page right before the TOC. To solve this, change it to: \clearpage\phantomsection\pdfbookmark{\contentsname}{toc} \tableofcontents –  dhst Mar 7 '12 at 20:02
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.
http://tex.stackexchange.com/questions/1820/contents-in-pdf-bookmarks
tex.stackexchange.com
crawl=CC-MAIN-2014-15
82565
application/http; msgtype=response
sha1:W4HOTDSSSLZ2F32HVIYA76ZJDXNILAOA
<urn:uuid:5568f4c5-469f-4618-97af-f4efac8d8e49>
2014-04-20T06:26:22Z
198.252.206.140
sha1:S5OQKYEWCLF6OKSCY47YAKDYUF4YKCVE
<urn:uuid:e11cae8d-5211-4c89-b7c8-6f1935d278a8>
http://tex.stackexchange.com/questions/1820/contents-in-pdf-bookmarks
response
<urn:uuid:cbcde997-6083-44e9-a92c-c342048bed1b>
robots: classic
hostname: ip-10-147-4-33.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2014-15
operator: CommonCrawl Admin
description: Wide crawl of the web with URLs provided by Blekko for April 2014
publisher: CommonCrawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf