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.

Inspired by question When do I need invoke \clearpage manually?:

When do I need to invoke \phantomsection?

In what condition is invoking \phantomsection necessary?

share|improve this question
    
Are there any other than hyperref applications? –  Grzegorz Wierzowiecki Feb 10 '12 at 12:24
    
See question in tex.stackexchange.com/questions/7627/how-to-reference-paragraph and my answer there for an example why you want to use \phantomsection{}. –  Peter M Oct 17 '12 at 13:00
add comment

3 Answers 3

The \phantomsection command is nessesary for hyperref to jump to the correct page, in other words it puts a hyper marker on the page. For example a starred section or chapter added to the TOC would normally refer to the wrong place without \phantomsection

\chapter*{Extended Summary}
\phantomsection
\addcontentsline{toc}{chapter}{Extended Summary}%
\markboth{Extended Summary}{Extended Summary}%

I normaly put in the preamble the command

\providecommand\phantomsection{}

Your document can then be compiled with or without hyperref without an error

share|improve this answer
14  
Especially elegant, your \providecommand –  Brent.Longborough Feb 10 '12 at 11:46
    
Is hyperref only application ? –  Grzegorz Wierzowiecki Feb 10 '12 at 12:24
    
@Grzegorz Wierzowiecki: Yes it is only nessesary for hyperref (hyperref defines it internaly) –  Danie Els Feb 10 '12 at 12:28
    
@GrzegorzWierzowiecki: If you're content with this information, don't forget to accept the answer. If there's something else you want to know, let us know. –  doncherry Mar 23 '12 at 2:06
2  
Since hyperref 2009/11/25 v6.79h \phantomsection is no longer necessary in this situation. With this usage, the anchor is put after the chapter title. –  Heiko Oberdiek Oct 17 '12 at 13:19
show 1 more comment

I am providing a different answer to this question because the original answer is out of date.

The \phantomsection command is needed to create a link to a place in the document that is not a figure, equation, table, section, subsection, chapter, etc.

This is mostly used in conjunction with \addcontentsline or with \label and \hyperref. For example, the following code will create a contents line and a link to somewhere in the document.

\phantomsection
\addcontentsline{toc}{section}{Some place in the document}
\label{some}
This is just \hyperref[some]{some place} in the document.

Without the \phantomsection line, both the contents line and the link would point to the beginning of the current section (or subsection, etc.)

In previous versions of hyperref (before 2009-11-25), you also had to use \phantomsection with unnumbered sections (e.g. \section*) to prevent links from pointing to the previous section. This is not necessary in up-to-date distributions.

share|improve this answer
add comment

I've found none of the previous answers to work, but the below snippet works well:

    \newpage
    \phantomsection \label{listoffig}
    \addcontentsline{toc}{chapter}{List of Figures}
    \listoffigures

Originally found on: http://sumanta679.wordpress.com/2009/05/15/latex-list-of-table-list-of-figures-and-bibliography-in-toc/

share|improve this answer
    
This looks very similar to the code Nathan Grigg posted: could you elaborate on the difference? –  Joseph Wright Mar 5 '13 at 8:01
    
I didn't get Nathans code to work. Why? I couldn't tell you. But here's a solution that worked for me. –  Robert Foss Mar 6 '13 at 15:51
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.