TransWikia.com

Linking the Table of Contents in LaTeX

TeX - LaTeX Asked by Chesso on December 17, 2020

I am trying to link my table of contents to the respective chapters etc. of my.tex file when exported as a .pdf. However, I have a problem with the link to my bibliography. The bibliography link in my table of contents becomes linked, however it gets linked to the section before it. My code is below. Any thoughts?

   documentclass[12pt]{report}
    usepackage{STAT3585,amsfonts}
    usepackage{graphicx}
    usepackage{pstcol}
    usepackage{float}
    usepackage{amsmath}
    usepackage{color}
    usepackage[colorlinks = true,
               linkcolor = black,
               urlcolor  = black,
               citecolor = blue,
               anchorcolor = blue]{hyperref}
    usepackage{cancel}
    usepackage{polynom}
    usepackage{amsthm}
    usepackage{multicol}
    usepackage{amssymb}
    usepackage{comment}
    
    
    newtheorem{thm}{Theorem}[chapter]
    newtheorem{lem}{Lemma}[chapter]
    newtheorem{exa}{Example}[chapter]
    newtheorem{cor}{Corollary}[chapter]
    newtheorem{note}{Note}[chapter]
    
    
    begin{document}

chapter{Introduction}

section{Basics}
    
    addcontentsline{toc}{chapter}{Bibliography}
    
    
    begin{thebibliography}{99}
    
    bibitem{} ....
    
    end{thebibliography}
    
    end{document}

One Answer

You can add a phantomsection to provide a target for the link to the bibliography. Make sure to use it (and your addcontentsline) on the same page as the bibliography and not the previous page like in your example. You can ensure this by adding clearpage before them.

   documentclass[12pt]{report}
    usepackage{amsfonts}
    usepackage{graphicx}
%    usepackage{pstcol}
    usepackage{float}
    usepackage{amsmath}
    usepackage{color}
    usepackage[colorlinks = true,
               linkcolor = black,
               urlcolor  = black,
               citecolor = blue,
               anchorcolor = blue]{hyperref}
    usepackage{cancel}
    usepackage{polynom}
    usepackage{amsthm}
    usepackage{multicol}
    usepackage{amssymb}
    usepackage{comment}
    
    
    newtheorem{thm}{Theorem}[chapter]
    newtheorem{lem}{Lemma}[chapter]
    newtheorem{exa}{Example}[chapter]
    newtheorem{cor}{Corollary}[chapter]
    newtheorem{note}{Note}[chapter]
    
    
    begin{document}

tableofcontents

chapter{Introduction}

section{Basics}
    
    
    cleardoublepage
    phantomsection
    addcontentsline{toc}{chapter}{Bibliography}
    
    
    begin{thebibliography}{99}
    
    bibitem{} ....
    
    end{thebibliography}
    
    end{document}

Correct answer by samcarter_is_at_topanswers.xyz on December 17, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP