# hyperref not working. It goes to wrong page

I dont understand why my hyperref is not going to the page I wanted when I click it on my table of content?

\documentclass[12pt, a4paper, oneside]{report}
\usepackage[T1]{fontenc}
\usepackage{mathptmx} %times font
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{enumerate}
\usepackage{hyperref}
\usepackage{setspace}
\usepackage[english]{babel} %roman & arabic label page
\usepackage[top=50mm , bottom=50mm, left=45mm, right=45mm]{geometry}

\addto\captionsenglish{% Replace "english" with the language you use
\renewcommand{\contentsname}%
}

\hypersetup{
linktoc=all,     %set to all if you want both sections and subsections linked
}

\pagenumbering{Roman}

\begin{document}
\input{CoverPage}
\thispagestyle{empty}
\pagebreak

\input{TitlePage}
\thispagestyle{empty}
\pagebreak

\setcounter{page}{1}
\pagebreak

\input{DeclarationPage}
\pagebreak

\input{AcknowledgementPage}
\pagebreak

\tableofcontents

\pagebreak

\listoffigures
\pagebreak

% % (1) =========================================
\pagenumbering{arabic}
\input{Introduction}
\setcounter{chapter}{1}
\pagebreak

• Using this way, you have to use a \phantomsection before the \addcontentsline..., but there might be more issues to solve. \addcontentsline should be done before you use \input and I would not use \pagebreak there. Replace it with \cleardoublepage – user31729 Aug 6 '15 at 7:27
• @ChristianHupfer i just tried.. it's not working.. aikss – Michimcchicken Aug 6 '15 at 7:29
• Yes, as I added: There is more work to do, probably. Your document is only a fragment, it's hard to help you. Do the files with \input have \chapter inside? – user31729 Aug 6 '15 at 7:29
• Yes, try that, but there's even a better way. I'll try a solution. – user31729 Aug 6 '15 at 7:32

There are multiple issues with the O.P. code...

• Use \cleardoublepage\phantomsection\addcontentsline{...} if some content must be explicitly added to a ToC
• For the Table of Contents and List of Figures \usepackage{tocbibind} is the cleaner solution
• The Introduction should be real chapter and not something with \section and subsection. This screws up the bookmarking etc. and numbering.
• The \input is too much for my taste -- It makes editing (and debugging) very difficult.

Some notes on \phantomsection etc.

If content is to be added to a .toc etc. file, \addcontentsline{toc}{...}{...} is most times the right choice. However, if this happens without a \cleardoublepage (or \clearpage) in conjunction with \phantomsection, the link will go to a previous page.

The \phantomsection can be omitted however, if a command like \chapter* etc. is used. An anchor related to chapter* is inserted by hyperref then. For more information, see section

3.2 Options for destination names

in the hyperref manual please.

\documentclass[12pt, a4paper, oneside]{report}
\usepackage[T1]{fontenc}
\usepackage{mathptmx} %times font
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{enumerate}
\usepackage{setspace}
\usepackage[english]{babel} %roman & arabic label page
\usepackage[top=50mm , bottom=50mm, left=45mm, right=45mm]{geometry}

\addto\captionsenglish{% Replace "english" with the language you use
\renewcommand{\contentsname}%
}

\title{Foo}
\author{Foo}

\usepackage{blindtext}
\usepackage{tocbibind}

\usepackage{hyperref}

\hypersetup{
linktoc=all,     %set to all if you want both sections and subsections linked
}

\pagenumbering{Roman}

\begin{document}
\input{CoverPage}
\thispagestyle{empty}
\cleardoublepage
\input{TitlePage}
\thispagestyle{empty}
\cleardoublepage

\phantomsection
\setcounter{page}{1}
\cleardoublepage

\phantomsection
\input{DeclarationPage}
\cleardoublepage

\phantomsection
\input{AcknowledgementPage}
\cleardoublepage

\tableofcontents
\cleardoublepage

\listoffigures
\cleardoublepage

% % (1) =========================================
\pagenumbering{arabic}
\phantomsection
\input{Introduction}
\setcounter{chapter}{1}  % Why???

\end{document}


For the individual FooPage.tex files I used basically this code

\chapter*{Foo}  % To make the page header outstanding, just for this solution
\blindtext[2]


Replace Foo with the relevant name (Exception: TitlePage.tex is \maketitle only)

The individual \phantomsection commands aren't necessary if \chapter* etc is used, but I kept them, since it's unclear what's inside the real \input{...} files.

• so you dont use the phantomsection anymore ah?? – Michimcchicken Aug 6 '15 at 8:08
• @Michimcchicken: Not everywhere. I'll update my code – user31729 Aug 6 '15 at 8:09
• what if i dont use tocbibind ? cause i dont know why the auto download not working.. – Michimcchicken Aug 6 '15 at 8:13
• btw the setcounter thing at the intro page is because i using different page numbering.. the pages before list of figures are using roman numbering and the introduciton page is using arabic and start from page 1.. haha required by my faculty.. dont ask me haha – Michimcchicken Aug 6 '15 at 8:15
• If you use don't use tocbibind then you have to use \addcontentsline... again. And you are setting the chapter number, not the page number ;-) – user31729 Aug 6 '15 at 8:17

I had the same problem, but with the particular wrong behavior just in the roman sections. The solution was to put the command \addcontentsline... after the title of roman sections and before in arabic sections.

• Welcome to TeX.SX! Could you add some context, detail and/or explanations for how the solution works exactly? Furthermore your answer would be way more helpful if you add some concrete code - even though it might seem "overkill". – Ruben Dec 13 '20 at 16:34

I had this problem only for a few sections and found that it was because of float specifier h! overriding internal parameter. e.g.

\begin{figure}[h!]
% My graphics
\end{figure}


Removing "!" actually solved the problem for me.