I am writing a thesis and I would like to put the title page and abstract into the table of contents. However, my title page hyperlink and abstract hyperlink both link to the title page.
Here is my main Latex file:
% main.tex================================================================
%preamble
\documentclass{my_thesis}
% preamble contains title page, signature page, acknowledgment and abstract texts
\usepackage{import}
% Pacakges used
\usepackage[utf8]{inputenc} % Remove warning on ascii conversion
\usepackage[T1]{fontenc} % Remove warning on ascii conversion
\usepackage[margin=1in,letterpaper]{geometry} % decreases margins
\usepackage{float} % for figure "H"
\usepackage{amsmath} % math
\usepackage{hyperref} % hyperlinks
\setlength{\parskip}{0.5em} % paragraph spacing
\usepackage{graphicx} % figure
\usepackage{subfig}
\usepackage[nottoc]{tocbibind} % put bib in the table of content
\usepackage{amsfonts} % for math equations
\usepackage{array} % table
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\usepackage{listings} % code
\newcommand{\myparagraph}[1]{\paragraph{#1}\mbox{}\\} % paragraph with line break
\begin{document}
% title page-------------------------------------------
\input{./Chapter_title/title_page.tex}
\addcontentsline{toc}{chapter}{Title Page}
% ----------------------------------------------------
% abstract -------------------------------------------
\input{./Chapter_abstract/abstract.tex}
\addcontentsline{toc}{chapter}{Abstract}
% ----------------------------------------------------
% acknowledgement ----------------------------------------
\input{./Chapter_acknowledgement/acknowledgement.tex}
\addcontentsline{toc}{chapter}{Acknowledgement}
% ----------------------------------------------------
% generate table of contents ============================
\setcounter{tocdepth}{5} % set the depth of table of contents
\tableofcontents
% ======================================================
\input{./Chapter_introduction/introduction.tex}
...
\end{document}
My title page file:
% title_page.tex================================================
\thispagestyle{empty}
\begin{titlepage}
\begin{center}
\vspace*{1cm}
{ \huge
\textbf{My Ttile}
}
...
\end{center}
\end{titlepage}
My abstract page file:
% abstract.tex=================================================
\thispagestyle{plain}
\begin{center}
\vspace*{1cm}
{ \Large
\textbf{My Title}
}
\vspace{0.4cm}
\large
by \\
\vspace{0.4cm}
\textbf{XXX}
\vspace{0.9cm}
\textbf{Abstract}
\end{center}
My abstract...
By doing so, I am able to see Title Page
and Abstract
in my table of contents. However, in the generated table of content, the Title Page
and Abstract
share the same page number 1
(see the figure below)? But I used \thispagestyle{empty}
in the title_page.tex
and there is no page number on the title page. The first page starts with the abstract page. And the hyperlinks of Title page
and Abstract
both link to the title page. Can anyone tell me how to fix this? Thank you!
Edit: I added a mini problem-replicate example here my_thesis if anyone want to have a closer look.
\input
the relevant contents of those files might as well be in your main example document. Plus you list no relevant preamble or document class.hyperref
(no preamble so we don't know), but then\addcontentsline{toc}{chapter}{Abstract}
has no anchor to point to. Try\phantomsection\addcontentsline{toc}{chapter}{Abstract}
instead. Additionally I'd add this right after\textbf{Abstract}
not in the main document after the\input
as the link then points towards the end of the file.\phantomsection\addcontentsline{toc}{chapter}{Abstract}
after\textbf{Abstract}
, this time the hyperlink can point to the right page. So what is the "anchor" ofhyperref
? It seems it always points to target like '\chapter' or\section
. Since myabstract.tex
does not have such a target so it has nowhere to point to?\addcontentsline
is executed it will take the current target. Normally\addcontentsline
sits inside say\chapter
and there\refstepcounter
will make an anchor/target for us. Here there is no anchor near\textbf{Abstract}
it will take the nearest one. which might be the nearest\section
etc.