# Getting Proper PDF Hyperrefs

What is the easiest way of including your listoffigures and listoftables in your tableofcontents to have it display

List of Figures ......... page number

I am using :

\documentclass{report}
\usepackage{lipsum}
\usepackage{hyperref}

\begin{document}
\tableofcontents
\listoffigures
\listoftables
\newpage

\chapter{Intro} \lipsum[1]

\section{Learning the Art of Thinking} \lipsum[2]

\end{document}


I'm not sure what part is for, but it seems to put a space between the LoF and LoT, because when taken out, they are side-by-side. I want the LoF and LoT to be in the TOC and just be formatted normally as if chapter or subsection with the correct page number. With the above code, the word "Figures" overwrites the \underline{page} which is not wanted.

-

The easiest way depends on the class you are using.

1st Alternative: If you are using a KOMA-Script class, the easiest way would be to use class option listof=totoc:

\documentclass[listof=totoc]{scrbook}

\usepackage{hyperref}
\AtBeginDocument{%
\protect\hspace*{\protect\fill}\protect\underline{page}%
\protect\par
}%
}
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\end{document}


I've used \hspace*{\fill} to right align the page. I cannot recommend doing something else at the example above, but nevertheless you may use another length than \fill, if don't want it right aligned. The \protect commands are only to prevent, e.g. \hspace from breaking at the moving argument of \addtocontents.

2nd Alternative: With memoir you simply don't have to use the star version of the commands:

\documentclass{memoir}

\usepackage{hyperref}
\AtBeginDocument{%
\protect\hspace*{\protect\fill}\protect\underline{page}%
\protect\par
}%
}
\begin{document}
\tableofcontents* % no entry to toc itself
\listoffigures
\listoftables
\end{document}


3rd Alternative: With standard classes you may use package tocbibind.

4th Alternative: Another solution may be:

\documentclass{book}

\AtBeginDocument{%
\protect\hspace*{\protect\fill}\protect\underline{page}%
\protect\par
}%
}
\begin{document}
\tableofcontents
\cleardoublepage% make sure to be on the correct page with the following two commands
\csname phantomsection\endcsname% anchor for links usings hyperref
\listoffigures
\cleardoublepage% make sure to be on the correct page with the following two commands
\csname phantomsection\endcsname% anchor for links usings hyperref
\listoftables
\end{document}


List of figures and list of tables are topmost level headings, usually may by \chapter* at report and book classes and \section* at article classes. Because of this, the toc entries of both should be top level entries. That's the reason I'm using chapter for the second argument of \addcontentsline at the example above using book class (with article class you should change it into section). Top level entries at book, report or article does not have dots between title and page number. But this depends on the class. So if you're using another class, the result may be another.

Addon to all those alternatives: And if you like to have dots at chapter entries with either KOMA-Script classes or standard classes you may use a package, e.g. add

\usepackage{tocstyle}
\usetocstyle{allwithdot}


at the example with scrbook or book above.

Here an working example using tocstyle with report (because you've told, that you're using this class) and the code above:

\documentclass{report}
\AtBeginDocument{%
\protect\hspace*{\protect\fill}\protect\underline{page}%
\protect\par
}%
}

\usepackage{tocstyle}
\usetocstyle{allwithdot}

\begin{document}
\tableofcontents
\cleardoublepage% make sure to be on the correct page with the following two commands
\csname phantomsection\endcsname% anchor for links usings hyperref
\listoffigures
\cleardoublepage% make sure to be on the correct page with the following two commands
\csname phantomsection\endcsname% anchor for links usings hyperref
\listoftables
\end{document}


with result:

And here the same using tocstyle and tocbibind and hyperref:

\documentclass{report}
\AtBeginDocument{%
\protect\hspace*{\protect\fill}\protect\underline{page}%
\protect\par
}%
}

\usepackage{tocbibind}
\usepackage{tocstyle}
\usetocstyle{allwithdot}
\usepackage{hyperref}

\begin{document}
\tableofcontents
\listoffigures
\listoftables
\end{document}


With result:

-
Thanks! Thats works. Three things. 1) How can one you adjust the horizontal spacing of where you would like the \underline{page}. 2) There are no \ldots after the LoF and LoT. 3) Also wold like if it can be flexible to do different things with the fonts of the LoF and LoT instead of being just one standard font and size. Oh, and one last thought, I also need one for an abstract page. How can you put that in TOC elegantly? It is right after LoT –  night owl Dec 13 '11 at 13:24
@nightowl it may help to tell Schweinebacke what documentclass you're using. –  Bruno Le Floch Dec 13 '11 at 17:19
@nightowl: I've already written at the first version of my answer: everything depends on the class you are using, e.g. using a KOMA-Script class you may use \setkomafont{chapterentry} to change the font of the chapter level entries. So please make a MWE and tell more about what you are doing. Nevertheless I've added some additional information to my answer. –  Schweinebacke Dec 13 '11 at 19:44
@nightowl: I've already explained at the answer, how to modify the horizontal positioning of \underline{page}. Simply replace \fill by the length you want. There was an typo at the tocstyle lines. Using allwithdot instead of allwithdots works with report as well. Simply add the lines to the scrbook example and replace scrbook by report shows it. See package manual for more information about predefined styles and how to change settings. Even combination of tocbibind and tocstyle does work. –  Schweinebacke Dec 14 '11 at 14:44
@nightowl: Sorry, but I cannot help you, if you don't tell me, what's the problem. Have you even tried my examples? What's the error message? I've added several examples to show, that tocstyle with standard class does not generally result in errors and even combination with tocbibind does work. –  Schweinebacke Dec 15 '11 at 9:43

Use tocbibind package, it works with book, report and article classes. From it's manual:

The tocbibind package enables the titles of the Table of Contents, the List of Figures, the List of Tables, the Bibliography and the Index all to be added to the Table of Contents. By default, all of these document elements, if they exist, will be incorporated into the Table of Contents (ToC for short). Package options are available to switch oﬀ any of these inclusions.

-
Hey! Thanks. That simple fix did the trick. Do you know if they have an option for putting dots like \usetocstyle{allwithdots} ?, as mentioned by Schweinebacke. –  night owl Dec 14 '11 at 14:11
@nightowl: I've already told you yesterday, that you may use tocbibind. And you may combine both packages (see my comment below my answer). –  Schweinebacke Dec 14 '11 at 14:49
@nightowl: I think Schweinebacke is right, in his first answer already mention tocbibind package plus some other options in case you don't use standard classes. I wrote this one because I didn't carefully read his message. It would be better to accept Schweinebacke answer. –  Ignasi Dec 14 '11 at 17:43
@nightowl: I've suggested to use tocbibind independent of tocstyle. Adding tocstyle has been done only because of your additional question how to add dots to the entries. –  Schweinebacke Dec 15 '11 at 9:48
@nightowl: I've never used tocbibind but looking for dots and \tableofcontents here I've found line of dots in table of contents. –  Ignasi Dec 15 '11 at 15:35

After your \listoftables or \listoffigures command you can manually add a ToC reference with:

\addcontentsline{toc}{sectiontype}{ToC Entry}


Depending on what depth your toc is set at, i.e. does it show chapters only, sections, subsection, etc... choose "sectiontype" to be one that is displayed appropriately for you.

"ToC Entry" is what you want displayed in your ToC.

So, for your tables you could use:

\addcontentsline{toc}{section}{List of Tables}

-
This wouldn't work if the list is longer than one page. –  egreg Dec 13 '11 at 19:06
I use this for a LOF that is ~3 pages @ 2 columns. –  Steve Dec 13 '11 at 19:15
@Steve: In this case the last page of you LOF will be added to the toc instead of the first one … –  Schweinebacke Dec 13 '11 at 19:28