Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LaTeX hyperref link goes to wrong page when i clicked at the content there

i would like to ask how to use the \hyperref because i've googled loads of loads of answers but i can't find. i've created my own TOC. then i included \hyperref package. Then the contents are automatically hyperlinks which is good. but then it went to the wrong pages. i've googled a lot but i couldn't find answer. The contents that i clicked goes to the wrong page.

\documentclass[10pt,a4paper]{report}

\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{enumerate}

\usepackage{hyperref}
% %\usepackage[colorlinks]{hyperref}


% %\renewcommand*{\contentsname}{\hyperlink{contents}{Contents}}
% %\renewcommand*{\contentsname}{\hyperref[contents]{\arabic{page}}}

\begin{document}

\input{coverPage}
\maketitle

\tableofcontents
\addcontentsline{toc}{chapter}{Table of Contents}
\pagebreak

\addcontentsline{toc}{chapter}{List of Figures}
\listoffigures
\pagebreak

% % (1) ==============================================
\setcounter{chapter}{1}
\addcontentsline{toc}{chapter}{1. Introduction}
\input{introduction}
\pagebreak

\addcontentsline{toc}{chapter}{2. References}
\input{references}
\pagebreak

\addcontentsline{toc}{chapter}{3. Glossary}
\input{glossary}
\pagebreak

\end{document}
like image 956
Michimcchicken Avatar asked Jan 04 '15 12:01

Michimcchicken


People also ask

How do you keep a link in LaTeX?

You can add a hyperlink into your LaTeX article using the command \usepackage{hyperref} and then including the command \href{YOUR URL}{TEXT FOR YOUR HYPERLINK}.

How do you make a link clickable in LaTeX?

Links to a web address or email can added to a LaTeX file using the \url command to display the actual link or \href to use a hidden link and show a word/sentence instead. There are two commands in the example that generate a link in the final document: \href{http://www.overleaf.com}{Something Linky}

What does Hyperref do in LaTeX?

Hyperref. The package hyperref provides LaTeX the ability to create hyperlinks within the document. It works with pdflatex and also with standard "latex" used with dvips and ghostscript or dvipdfm to build a PDF file.

Can we change color of a hyperlink using LaTeX if so how select one?

Changing LaTeX Hyperlink Color Generally, default color is OK. However, if you wish to change the default settings of hyperlink color, you have to use \hypersetup command in your document preamble.


1 Answers

The issue here is that \chapter sets itself on a new page, so issuing \addcontentsline{toc}{chapter}{<chapter title>} before \chapter may point to an incorrect page.

Also, your \tableofcontents might be more than a single page. So, issuing \addcontentsline{toc}{chapter}{Table of Contents} after \tableofcontents - a \chapter* - might again point to an incorrect page.

The best solution is to use the following setup:

\cleardoublepage
\addcontentsline{toc}{chapter}{<chapter title>}
% <your \chapter or \chapter*>

This will ensure that \addcontentsline is issued on the same page as \chapter or \chapter*.

like image 98
Werner Avatar answered Oct 12 '22 22:10

Werner