[Tex/LaTex] Using setspace package breaks footnotes link

footnoteshyperrefsetspace

The following code created a footnote, the problem is that in the produced pdf file clicking footnote reference 1 doesn't jump to footnote definition1 in bottom of the page, instead, it jumps to the beginning of the pdf file. But if I remove the "\usepackage{setspace}" line everything works. Why is this and how to make it work as I expected? Thanks in advance.

\documentclass[11pt]{article}
\usepackage{hyperref}
\tolerance=1000
\usepackage{setspace}
\title{temp}
\hypersetup{
  colorlinks,%
  citecolor=black,%
  filecolor=black,%
  linkcolor=blue,%
  urlcolor=black
}
\begin{document}

\maketitle
\tableofcontents

\section{Section 1}
\label{sec-1}
TeX is a computer program for typesetting documents, created by Donald Knuth. It
takes a suitably prepared computer file and converts it to a form which may be
printed on many kinds of printers, including dot-matrix printers, laser printers
and high-resolution typesetting machines. LaTeX is a set of macros for TeX that
aims at reducing the user's task to the sole role of writing the content, LaTeX
taking care of all the formatting process. A number of well-established
publishers now use TeX or LaTeX to typeset books and mathematical journals. It
is also well appreciated by users caring about typography, consistent
formatting, efficient collaborative writing and open formats.

\section{Section 2}
\label{sec-2}
TeX is a computer program for typesetting documents, created by Donald Knuth. It
takes a suitably prepared computer file and converts it to a form which may be
printed on many kinds of printers, including dot-matrix printers, laser printers
and high-resolution typesetting machines. LaTeX is a set of macros for TeX that
aims at reducing the user's task to the sole role of writing the content, LaTeX
taking care of all the formatting process. A number of well-established
publishers now use TeX or LaTeX to typeset books and mathematical journals. It
is also well appreciated by users caring about typography, consistent
formatting, efficient collaborative writing and open formats.

\section{Section 3}
\label{sec-3}
TeX is a computer program for typesetting documents, created by Donald Knuth. It
takes a suitably prepared computer file and converts it to a form which may be
printed on many kinds of printers, including dot-matrix printers, laser printers
and high-resolution typesetting machines. LaTeX is a set of macros for TeX that
aims at reducing the user's task to the sole role of writing the content, LaTeX
taking care of all the formatting process. A number of well-established
publishers now use TeX or LaTeX to typeset books and mathematical journals. It
is also well appreciated by users caring about typography, consistent
formatting, efficient collaborative writing and open formats.

\section{Test footnotes}
\label{sec-4}
This text has a footnote \footnote{See section \ref{sec-1}}
\end{document}

Best Answer

The package setspace modifies the standard definition of \footnote so that single spacing is used in the footnote texts. Also hyperref modifies \footnote so as to make the hyperlinks.

However, hyperref is generally agnostic about the definition of the commands it has to redefine for doing its job (there are many): it just takes the current definition and massages it a bit for adding the hyperlinks.

If you load the package setspace after hyperref, the modification made by the former overrides the change made by the latter. So the correct way is first loading setspace and then hyperref.

There are some packages that should be loaded after hyperref, you find a big list at Which packages should be loaded after hyperref instead of before? and setspace doesn't appear there.

\documentclass[11pt]{article}

\usepackage{setspace}
\usepackage{hyperref}
\hypersetup{
  colorlinks,%
  citecolor=black,%
  filecolor=black,%
  linkcolor=blue,%
  urlcolor=black
}

%\tolerance=1000 %%% Are you really sure?


\title{temp}

\begin{document}

\maketitle
\tableofcontents

\section{Section 1}
\label{sec-1}
TeX is a computer program for typesetting documents, created by Donald Knuth. It
takes a suitably prepared computer file and converts it to a form which may be
printed on many kinds of printers, including dot-matrix printers, laser printers
and high-resolution typesetting machines. LaTeX is a set of macros for TeX that
aims at reducing the user's task to the sole role of writing the content, LaTeX
taking care of all the formatting process. A number of well-established
publishers now use TeX or LaTeX to typeset books and mathematical journals. It
is also well appreciated by users caring about typography, consistent
formatting, efficient collaborative writing and open formats.

\section{Section 2}
\label{sec-2}
TeX is a computer program for typesetting documents, created by Donald Knuth. It
takes a suitably prepared computer file and converts it to a form which may be
printed on many kinds of printers, including dot-matrix printers, laser printers
and high-resolution typesetting machines. LaTeX is a set of macros for TeX that
aims at reducing the user's task to the sole role of writing the content, LaTeX
taking care of all the formatting process. A number of well-established
publishers now use TeX or LaTeX to typeset books and mathematical journals. It
is also well appreciated by users caring about typography, consistent
formatting, efficient collaborative writing and open formats.

\section{Section 3}
\label{sec-3}
TeX is a computer program for typesetting documents, created by Donald Knuth. It
takes a suitably prepared computer file and converts it to a form which may be
printed on many kinds of printers, including dot-matrix printers, laser printers
and high-resolution typesetting machines. LaTeX is a set of macros for TeX that
aims at reducing the user's task to the sole role of writing the content, LaTeX
taking care of all the formatting process. A number of well-established
publishers now use TeX or LaTeX to typeset books and mathematical journals. It
is also well appreciated by users caring about typography, consistent
formatting, efficient collaborative writing and open formats.

\section{Test footnotes}
\label{sec-4}
This text has a footnote \footnote{See section \ref{sec-1}}
\end{document}

By the way, are you really sure about \tolerance=1000? It's quite a large value and you'll risk getting wide interword spaces. It's better to do

\usepackage{microtype}

(before loading hyperref).