Add \cleardoublepage\phantomsection
before \listoftables
.
A \phantomsection
seems not to be necessary before \chapter*
. The amsbook class is slightly different from book, in that it puts all chapters, numbered or not, in the table of contents. This also creates correctly the anchors for them, but \listoftables
and \listoffigures
don't use \chapter*
internally and so the anchors for them are not created.
It's also good to load the bookmark package after hyperref: it simplifies bookmark management.
Since you are setting secnumdepth
to zero, no anchors are generated for the hyperlinks and this produces the undesired effect mentioned; the following code works as expected:
\documentclass{report}
\usepackage[linktoc=all]{hyperref}
\usepackage{titlesec}
\hypersetup{
colorlinks,
citecolor=black,
filecolor=black,
linkcolor=black,
urlcolor=black
}
\begin{document}
\tableofcontents
\chapter{test}
Test text
\newpage
\section{A section}
Lorem Ipsum
\newpage
\subsection{This link is correct}
\end{document}
If you want to have all your sections and subsections to be unnumbered but included in the ToC and stll generating the correct hyperlinks, one option would be to use the \phantomsection
command to generate the anchors:
\documentclass{report}
\usepackage[linktoc=all]{hyperref}
\setcounter{secnumdepth}{0}
\usepackage{titlesec}
\hypersetup{
colorlinks,
citecolor=black,
filecolor=black,
linkcolor=black,
urlcolor=black
}
\begin{document}
\tableofcontents
\chapter{test}
Test text
\newpage
\phantomsection
\section{A section}
Lorem Ipsum
\newpage
\phantomsection
\subsection{This link is correct}
\end{document}
Another option would be to use the titlesec
and titletoc
packages to remove the numbering from both the document body and the ToC:
\documentclass{report}
\usepackage[linktoc=all]{hyperref}
\usepackage{titlesec}
\usepackage{titletoc}
\titleformat{\section}
{\normalfont\Large\bfseries}{}{1em}{}
\titleformat{\subsection}
{\normalfont\large\bfseries}{}{1em}{}
\titlecontents{section}
[1.5em] {}{}{}
{\titlerule*[1em]{.}\contentspage}
\titlecontents{subsection}
[3.8em] {}{}{}
{\titlerule*[1em]{.}\contentspage}
\hypersetup{
colorlinks,
citecolor=black,
filecolor=black,
linkcolor=black,
urlcolor=black
}
\begin{document}
\tableofcontents
\chapter{test}
Test text
\newpage
\section{A section}
Lorem Ipsum
\newpage
\subsection{This link is correct}
\end{document}
Yet another option would be to use the starred versions of the sectional units (i.e., \section*
, \subsection*
) and to use \addcontentsline
to manually add the entries to the ToC:
\documentclass{report}
\usepackage[linktoc=all]{hyperref}
\hypersetup{
colorlinks,
citecolor=black,
filecolor=black,
linkcolor=black,
urlcolor=black
}
\begin{document}
\tableofcontents
\chapter{test}
Test text
\newpage
\section*{A section}
\addcontentsline{toc}{section}{A section}
Lorem Ipsum
\newpage
\subsection*{This link is correct}
\addcontentsline{toc}{subsection}{This link is correct}
\end{document}
Best Answer
This is only a partial answer, but it is kind of a roadmap how this could be achieved.
First, note that the
hyperref
package does not offer a "standard way" to do such a thing. It only offers border styles for links (including underlining a link as explained here: How can I have colored and underlined links with hyperref?). One of the reasons for this might be that the PDF standard offers such border styles directly for link annotations, but to obtain a non-border style, you need to use appearance streams and form XObjects instead. The documentation of such streams and objects can be found here: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf (start at page 612 for appearance streams and page 355 for form XObjects)What needs to be done is the following: Find out how the PDF output must look like for a link to have a background color (fortunately, appearance streams already offer three different modes, including one for being inactive and one for hovering over the object; thus, the "action logic" you need is already implemented within the PDF standard and you only need to provide the attributes implementing your desired look).
Then change the corresponding part of the
hyperref
package by redefining some of its commands as in the "automatic" part of this answer: How can I have colored and underlined links with hyperref?You can find the source code of the
hyperref
package here: http://www.ctan.org/pkg/hyperrefSince both the PDF standard and the
hyperref
package are quite huge, it might involve a significant amount of time just to find the right attributes and commands where to plug these things together, though.In any case, such a solution might not work with every PDF viewer as most of them do not implement everything that is written in the PDF standard. As long as you only use background color, however, it might work for many viewers (but no guarantees given).