# Table of contents doesn't link to references

I am writing my thesis in Latex and I am having trouble getting the table of contents to correctly link to the reference list I created with the apacite package. A MWE that illustrates my problem:

\documentclass[12pt,oneside,english]{article}
\usepackage[a4paper,margin=25mm]{geometry}
\usepackage[english]{babel}

\usepackage{titlesec}
\newcommand\sectionbreak{\clearpage}
\usepackage[nottoc,notlof,notlot]{tocbibind}
\usepackage[toc]{appendix}
\renewcommand{\setthesubsection}{\Alph{subsection}}

\usepackage{hyperref}
\usepackage{cleveref}
\crefname{appsec}{Appendix}{Appendices}

\usepackage{blindtext}
\usepackage[natbibapa]{apacite}
\usepackage[]{setspace}

\usepackage{filecontents}

\begin{filecontents}{jobname.bib}
@book{author_book,
title = {Book's title},
author = {Author, Some},
location = {The City},
publisher = {Publisher},
date = {2005},
}
\end{filecontents}
\begin{document}

% Table of contents
\clearpage
\pdfbookmark[1]{Contents}{toc}
\tableofcontents

% Sections
\section{The first section}
Some text is need to push the section title to the next page \citep{author_book}. \hyperref[sec:references]{This} link to the references actually links to the second section. Why is that?
\section{The second section}
Again, some text.

% Bibliography
\begin{singlespacing}
\raggedright{
\bibliographystyle{apacite}
\bibliography{jobname}}\label{sec:references}
\end{singlespacing}

% Appendices
\appendices
\subappendices
\crefalias{section}{appsec}
\section*{Appendices}
\subsection{Some tables}\label[appsec]{app:tables}
This should actually be a table.

\subsection{Some more figures}
And here could be a figure.
\end{document}


I removed anything that I was sure is unrelated to the problem. As you can see, the page numbers in the table of contents are correct, but clicking on "References" actually links the the second before the bibliography. The same with the hyperref link in the first section. Some things I tried are not using the tocbibind package, and using an \addcontentsline in the bibliography, but that didn't work.

## 2 Answers

You need to add an anchor with \phantomsection for the links - as the bibliography is unnumbered this is not done automatically by hyperref:

\clearpage
\phantomsection %anchor
\begin{singlespacing}
\raggedright
\bibliographystyle{apacite}
\bibliography{jobname}\label{sec:references}
\end{singlespacing}

• For the bibliography this is true, it'll need \phantomsection, too. – Skillmon Mar 31 at 14:01

Using a \clearpage before the \appendices should work:

\documentclass[12pt,oneside,english]{article}
\usepackage[a4paper,margin=25mm]{geometry}
\usepackage[english]{babel}

\usepackage{titlesec}
\newcommand\sectionbreak{\clearpage}
\usepackage[nottoc,notlof,notlot]{tocbibind}
\usepackage[toc]{appendix}
\renewcommand{\setthesubsection}{\Alph{subsection}}

\usepackage{hyperref}
\usepackage{cleveref}
\crefname{appsec}{Appendix}{Appendices}

\usepackage{blindtext}
\usepackage[natbibapa]{apacite}
\usepackage[]{setspace}

\usepackage{filecontents}

\begin{filecontents}{jobname.bib}
@book{author_book,
title = {Book's title},
author = {Author, Some},
location = {The City},
publisher = {Publisher},
date = {2005},
}
\end{filecontents}
\begin{document}

% Table of contents
\clearpage
\pdfbookmark[1]{Contents}{toc}
\tableofcontents

% Sections
\section{The first section}
Some text is need to push the section title to the next page \citep{author_book}. \hyperref[sec:references]{This} link to the references actually links to the second section. Why is that?
\section{The second section}
Again, some text.

% Bibliography
\begin{singlespacing}
\raggedright{
\bibliographystyle{apacite}
\bibliography{jobname}}\label{sec:references}
\end{singlespacing}

% Appendices
\clearpage
\appendices
\subappendices
\crefalias{section}{appsec}
\section*{Appendices}
\subsection{Some tables}\label[appsec]{app:tables}
This should actually be a table.

\subsection{Some more figures}
And here could be a figure.
\end{document}