Graphics, Figures & TablesAdd table of contents to table of contents

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ptha
Posts: 5
Joined: Tue Mar 30, 2010 2:40 am

Add table of contents to table of contents

Post by ptha »

Hi I'm writing my thesis using Latex (Kile on Ubuntu) and
I want have the table of contents actually appear as an entry in the table of contents.

I've tried \addcontentsline{toc}{chapter}{Contents} with no joy.

I'm sorry if this is a ridiculous question, but have mercy I'm a newbie...
P

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Add table of contents to table of contents

Post by gmedina »

Hi,

you forgot to mention the document class that you are using (crucial information not to be forgotten again). The tocbibind package could be useful for you:

Code: Select all

\documentclass{book}
\usepackage{tocbibind}

\begin{document}
\tableofcontents

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: Add table of contents to table of contents

Post by frabjous »

Could you be a little more specific about your lack of joy? What happened when you tried that line?
ptha
Posts: 5
Joined: Tue Mar 30, 2010 2:40 am

Add table of contents to table of contents

Post by ptha »

Sorry guys here's my document class it's a template for a thesis for my university:
tcd-phd-thesis.cls
(3.04 KiB) Downloaded 509 times
The code in my main tex file is

Code: Select all

\documentclass[twoside]{tcd-phd-thesis}
\usepackage[breaklinks]{hyperref}
\usepackage{cite}
\usepackage[style=altlist,
nonumberlist,
acronym,
toc]
{glossaries}

\input{acronyms}
\makeglossaries

\begin{document}

\input{title}

\frontmatter

\cleardoublepage

\input{declaration}
\addcontentsline{toc}{chapter}{Declaration}

\cleardoublepage
\input{summary}
\addcontentsline{toc}{chapter}{Summary}

\cleardoublepage
\input{acknowledgements}
\addcontentsline{toc}{chapter}{Acknowledgements}

\mainmatter

\renewcommand{\contentsname}{Table of Contents}
\tableofcontents

\renewcommand{\acronymname}{Abbreviations}
\printglossaries

\input introduction
\input crawling_and_classification
\input indexing
\input open_source_tools
\input research

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Bibliography}

\bibliographystyle{apalike}
\bibliography{references}

\end{document}
If I'm doing anything silly let me know.
ptha
Posts: 5
Joined: Tue Mar 30, 2010 2:40 am

Add table of contents to table of contents

Post by ptha »

frabjous wrote:Could you be a little more specific about your lack of joy? What happened when you tried that line?
When I tried the line above it just added an entry "Contents" to the toc, but it wasn't the actual table of contents - it listed the wrong page, and when clicking on the link it went to a blank page rather the the start of the toc.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Add table of contents to table of contents

Post by frabjous »

You don't want \mainmatter to be in between this, and where you actually insert the table of contents. You'll also need a \cleardoublepage and \phantomsection before it. Depending on what kind of page numbering you want for the TOC, you want either:

Code: Select all

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Acknowledgements}
\input{acknowledgements}
\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Contents}
\renewcommand{\contentsname}{Table of Contents}
\tableofcontents

\mainmatter
or

Code: Select all

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Acknowledgements}
\input{acknowledgements}

\mainmatter
\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Contents}
\renewcommand{\contentsname}{Table of Contents}
\tableofcontents
I can't test though, since a MWE is useless if it's using input commands to call documents we don't have access to.
ptha
Posts: 5
Joined: Tue Mar 30, 2010 2:40 am

Add table of contents to table of contents

Post by ptha »

frabjous wrote:You don't want \mainmatter to be in between this, and where you actually insert the table of contents. You'll also need a \cleardoublepage and \phantomsection before it. Depending on what kind of page numbering you want for the TOC, you want either:

Code: Select all

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Acknowledgements}
\input{acknowledgements}
\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Contents}
\renewcommand{\contentsname}{Table of Contents}
\tableofcontents

\mainmatter
or

Code: Select all

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Acknowledgements}
\input{acknowledgements}

\mainmatter
\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Contents}
\renewcommand{\contentsname}{Table of Contents}
\tableofcontents
I can't test though, since a MWE is useless if it's using input commands to call documents we don't have access to.
I went with your first code example - and it works! - it think it was the addition of the \phantomsection that did it, many thanks!
Peter.
Post Reply