Text Formattinghyperref links wrong

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

hyperref links wrong

Post by svend_tveskaeg »

Hi all.

Consider the following MWE:

Code: Select all

\documentclass[a4paper,12pt,danish]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage[nottoc]{tocbibind}
\usepackage{hyperref}

\makeatletter
  \@addtoreset{section}{part}
\makeatother
\titlecontents{section}[2em]{}{\contentslabel{2em}}{\hspace*{-2em}}{\titlerule*[1pc]{.}\contentspage}
\renewcommand{\thepart}{\arabic{part}}
\renewcommand{\thesection}{\thepart.\arabic{section}}

\begin{document}

\begin{center}
\Huge Frontpage
\end{center}
\newpage

\pagenumbering{roman}

\titleformat*{\section}{\centering\bf\Huge}
\tableofcontents
\titleformat*{\section}{\bfseries\Large}
\newpage

\section*{Introduction}
\label{intro}
\addcontentsline{toc}{section}{Introduction}

\pagenumbering{arabic}

\part{Horse}
\label{horse}
\vspace{60pt}

\section{Goat}
\label{goat}
\newpage

\addtocontents{toc}{\protect\addvspace{24pt}}

\begin{thebibliography}{}
\label{bib}

\bibitem{illeris2005} Illeris, Knud:
\newblock {\slshape Læring og lærerroller};
  {\itshape Unge Pædagoger}~{\bfseries 8} (2005), 3--18.

\end{thebibliography}

\end{document}
Two of the interactive title in the ToC are not linking (is this an actual word?) to the correct place in the document; clicking on `Introduction' gets me to the frontpage and clicking on `Litteratur' gets me to the `Goat' section.
In general: Every (interactive) ToC entry before the first part gets my to the frontpage and the (interactive) bibliography entry in the ToC gets me to the last section title before the bib.

How to I get the correct "linking" in the ToC?

Thank you in advance!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

hyperref links wrong

Post by Stefan Kottwitz »

Hi,

Clemens already told you in another topic today, that you need \phantomsection. Perhaps you did not read it. Also, the order of commands is important. You can make it like this:

Code: Select all

\clearpage
\phantomsection
\addcontentsline{toc}{section}{Introduction}
\section*{Introduction}
\label{intro}
Stefan

PS: I know you mark your topics as solved finally, that's great. We got a new feature for this, which makes it easier: a solved button and filter. Perhaps try it at the other topic from today, and perhaps this one.
LaTeX.org admin
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: Wrong "linking"

Post by svend_tveskaeg »

Thank you, Stefan!

I most admit that I only read Thorsten's answar, as you figured.

I have now used the new "solved" method (I think); thanks for the hint! Please let me know if I have done something wrong.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: Wrong "linking"

Post by svend_tveskaeg »

Damn! I will now try again.

Better? ;)
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

hyperref links wrong

Post by Stefan Kottwitz »

svend_tveskaeg wrote: Better? ;)
Not yet, the checkmark is next to your post heading, not next to the solution post hesding. Try again ...? You an "unmark" and mark the other answer.

It's similar to your question: wrong linking - choosing the right answer for the check mark is great linking. Besides the check mark, it's the link. I know, it's new and a bit unusual still.

Stefan
LaTeX.org admin
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: Wrong "linking"

Post by svend_tveskaeg »

Now?
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Wrong "linking"

Post by Stefan Kottwitz »

Yes, perfect! :D

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

hyperref links wrong

Post by localghost »

svend_tveskaeg wrote:[…] I most admit that I only read Thorsten's answar, as you figured. […]
Just for the record. My solution for the standard classes also contains the \phantomsection command.


Thorsten
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: Wrong "linking"

Post by svend_tveskaeg »

@Thorsten.
I see; thanks!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply