Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect hyperlinking in LaTeX

So far the hyperref package in LaTeX has automatically linked all the items in my report correctly. But there is one that did not get linked properly, possibly because I manually added it to the table of contents like this:

\addcontentsline{toc}{chapter}{Bibliography}

How do I fix this?

like image 766
alamodey Avatar asked Jul 16 '26 00:07

alamodey


2 Answers

You have to use the \phantomsection macro just before or after the \addtocontentsline. This instructs hyperref to add an anchor at that point. Also, take into account that you have to run LaTeX several times to make this anchor to be in the exact place.

like image 79
Diego Sevilla Avatar answered Jul 18 '26 18:07

Diego Sevilla


If you're using a standard LaTeX document class, such as report, you can use the tocbibind package, and then you won't need the \addcontentsline command and the hyperlinks should work correctly. From the documentation:

The tocbibind package enables the titles of the Table of Contents, the List of Figure, the List of Tables, the Bibliography and the Index all to be added to the Table of Contents.

I'd also suggest looking at the memoir class, which also solves this problem. It's intended to be a replacement for the standard report and book classes, and provides lots of options and commands for customisation.

like image 36
ChrisN Avatar answered Jul 18 '26 18:07

ChrisN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!