1

I'm getting a warning during compilation from the hyperref package and would like to solve it. Here's a MWE showing the issue:

\documentclass[11pt,twoside]{book} \usepackage[T1]{fontenc} \usepackage[nomath]{lmodern} \usepackage[french]{babel} \usepackage[letterpaper,left=1.25in,right=1in,top=0.5in,bottom=0.5in,includeheadfoot,headheight=14pt]{geometry} % Option showframe pour montrer les bordures. \usepackage{amssymb} \usepackage[dvipsnames,table]{xcolor} \usepackage{hyperref} \usepackage[pagestyles,medium]{titlesec} \begin{document} \setcounter{tocdepth}{2} \tableofcontents \cleardoublepage \phantomsection \pagestyle{plain} \section*{\centering Introduction} % Need to be shown in the ToC \addcontentsline{toc}{chapter}{\textbf{Introduction}} Blabla \subsection*{\textsf{Remerciements}} % Need to be shown in the ToC. \addcontentsline{toc}{section}{\textsf{Remerciements}} Text \chapter{Chapter title} Text \end{document} 

From this code, I'm getting the following pesky warning:

Package hyperref Warning: The anchor of a bookmark and its parent's must not (hyperref) be the same. Added a new anchor on input line 31. 

How can I fix this?

5
  • 2
    unnumbered sections do not work properly if titlesec is used, see 11.1.33 of the hyperref documentation. Commented Jun 24 at 19:14
  • @UlrikeFischer, I need titlesec for other things and the section above shoulnd't have a number. What should be a proper solution? Commented Jun 24 at 19:15
  • 2
    convince titlesec to properly support hyperref. Commented Jun 24 at 19:21
  • @UlrikeFischer and how should I do that? You're implying there's currently no solution to this issue? Commented Jun 24 at 19:23
  • @Cham you could not use titlesec? it will be much easier to do without titlesec than without hyperref. disclaimer: I strongly dislike titlesec, so I could delete the 'than without hyperref'. Commented Jun 24 at 21:07

1 Answer 1

1

Use bookmark (and a further \phantomsection). I'd load titlesec before hyperref. I'd also load amsmath in every math intensive document.

\documentclass[11pt,twoside]{book} \usepackage[T1]{fontenc} \usepackage[nomath]{lmodern} \usepackage[french]{babel} \usepackage[ letterpaper, left=1.25in, right=1in, top=0.5in, bottom=0.5in, includeheadfoot, headheight=14pt ]{geometry} % Option showframe pour montrer les bordures. \usepackage{amssymb} \usepackage[dvipsnames,table]{xcolor} \usepackage[pagestyles,medium]{titlesec} \usepackage{hyperref} \usepackage{bookmark} \setcounter{tocdepth}{2} \begin{document} \tableofcontents \cleardoublepage \pagestyle{plain} \phantomsection \section*{\centering Introduction} % Need to be shown in the ToC \addcontentsline{toc}{chapter}{\textbf{Introduction}} Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla Blabla \subsection*{\phantomsection \textsf{Remerciements}} % Need to be shown in the ToC. \addcontentsline{toc}{section}{\textsf{Remerciements}} Text \chapter{Chapter title} Text \end{document} 

The image shows what happens when hovering over the “Remerciement” part in the TOC. No warning appears in the log.

output

12
  • Apparently, I don't need to add the bookmark package. The warning are gone after moving the titlesoc package before the hyperref package, and adding the \phantomsection (which appears to be the solution to the issue). Commented Jun 24 at 21:08
  • is that just how your viewer shows links? or is that supposed to be a problem? I can't tell whether 'no warning appears in the log' means 'but it should' or 'so the problem is solved'. Commented Jun 24 at 21:13
  • 1
    the phantomsection can end up on the wrong page if the subsection is at a page break and then the bookmark will point to the previous page. Commented Jun 24 at 21:17
  • @Cham bookmark provides improved bookmarks and produces them on first compilation. it is recommended in hyperref's documentation. it will also load hyperref, so you can just replace hyperref with bookmark in your preamble. Commented Jun 24 at 21:19
  • 1
    @Cham well, it is fine to load hyperref first. or you can \PassOptionToPackage{<options>}{hyperref}. but by all means load hyperref separately if you want to specify options. bookmark just enables a better way of managing bookmarks. Commented Jun 24 at 21:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.