In my thesis template, the dedication and acknowledgements are chapter*{} while other chapters are chapter{}. The problem comes using the hyperref-bookmarks. What happens is the table of contents, appear nested in the acknowledgement section.
The list of figure nests in the table of contents, and the list of tables in list of figures.
[Tex/LaTex] how to end chapter* and start chapter
chaptershyperrefthesis
Related Solutions
The linked post (which has an answer by me too) is not a solution to the problem, but it can be used as a starter.
The main problem is that a \bookmark
command will enter the relevant information at the current level of the bookmark tree, this means the figure bookmarks will appear right between a chapter
or section
bookmark, but are not ordered or form a tree of themselves.
This can be cured by postponing the bookmark operation to some other place and faking some list of figure bookmark
etc, which is doing the right bookmark entries at the end if \listoffiguresbookmarks
is called at the end. (The same is true for \listoftablesbookmarks
.)
\documentclass{article}
\usepackage{caption}
\usepackage{etoolbox}
\usepackage[notlof,notlot]{tocbibind}
\usepackage[bookmarksnumbered,bookmarksopen=true]{hyperref}
\hypersetup{colorlinks,
linkcolor=blue,
linktoc=page}
\usepackage{bookmark}
\makeatletter
\newcommand{\listoffiguresbookmarks}{%
\pdfbookmark[0]{\listfigurename}{listoffiguresbookmark}
\bookmarksetup{level=1}
\@starttoc{lofb}
}
\newcommand{\listoftablesbookmarks}{%
\pdfbookmark[0]{\listtablename}{listoftablesbookmark}
\bookmarksetup{level=1}
\@starttoc{lotb}
}
\makeatother
%%% Generate bookmarks for all figures and tables
\makeatletter
\pretocmd\endfigure{%
\addtocontents{lofb}{%
\protect{%
\bookmark[
rellevel=1,
keeplevel,
dest=\@currentHref,
]{Figure \thefigure: \@currentlabelname}}}%
}{}{\errmessage{Patching \noexpand\endfigure failed}}
\pretocmd\endtable{%
\addtocontents{lotb}{%
\protect{%
\bookmark[
rellevel=1,
keeplevel,
dest=\@currentHref,
]{Table \thetable: \@currentlabelname}}}%
}{}{\errmessage{Patching \noexpand\endtable failed}}
\makeatother
\AtEndDocument{%
\listoffiguresbookmarks
\listoftablesbookmarks
}
\begin{document}
\tableofcontents
\listoffigures
\newpage
\section{The document}
\begin{figure}[ht]
\centering
\rule{6cm}{3cm}
\caption{Figure caption text}
\end{figure}
\newpage
\section{Different section}
\begin{figure}[ht]
\centering
\rule{6cm}{3cm}
\caption{Figure caption text 2}
\end{figure}
\clearpage
\begin{table}[ht]
\centering
\caption{Table caption No. 1}
\end{table}
\end{document}
1- The above code adds the pages abstract, acknowledgements, dedication to the table of contents, but when I click, they don't take me to the right page.
You need to insert a \phantomsection
instruction immediately after \chapter*{Abstract}
, chapter*{Dedication}
, \chapter*{Acknowledgments}
, etc. This should happen, obviously, inside the files Abstract.tex
, Dedication.tex
, Acknowledgments.tex
, etc.
2- I am not able to add table of contents to table of contents.
I suggest you load the tocbibind
package with the option notindex
:
\usepackage[notindex]{tocbibind}
This setup also provides for insertion of entries for the list of figures, the list of tables, and the bibliography in the table of contents. I.e., you will no longer need to provide the instruction \addcontentsline{toc}{chapter}{\listfigurename}
.
Of course, if your document does contain an (unnumbered) index and if you wish to show this (unnumbered) entity, you can omit the option notindex
.
3- For some reason, Abbreviations (which has two pages) is listed after the chapter 1 in table of contents. When I click it, it only takes me to page 2 of abbreviation.
This is happening because the instruction \addcontentsline {toc}{chapter}{Abbreviations}
occurs too late, viz., after both pages of abbreviations have been generated by LaTeX. I suggest you move \addcontentsline {toc}{chapter}{Abbreviations}
into file Abbreviations.tex
and execute it right after \chapter*{Abbreviations}
.
You should probably also insert the instruction \clearpage
(or \cleardoublepage
) immediately before \pagenumbering{arabic}
.
Best Answer
Maybe not the most elegant solution ...