3

I have a document with a standard TOC generated automatically by pdflatex but by default this TOC does not include lists of figures, tables and the bibliography.

So I am trying to force these manually using \addcontentsline{toc}{chapter}{List of Tables} in the preamble, e.g.

\addcontentsline{toc}{chapter}{List of Tables}
\listoftables

But what I am finding is that although the lists are included in the TOC, the page numbers tend to be one less than they should be. So if the TOC shows the List of Tables on page iv, the link in the TOC takes me to page iv which is titled List of Figures. In the TOC, the List of Figures is given as page iii.

The LaTeX MWE below illustrates what is happening.

A related issue is the page number of the bibliography. The TOC shows it to be on page 14 but page 14 actually displays the Results chapter.

The body of the document is fine and the titles appear correctly on the pages. So it must be something I am not doing, or doing wrong, with the \addcontentsline{...} lines.

Can anyone suggest anything?

MWE code:

    \documentclass[oneside,12pt]{report} % Use twoside for alternate page headings.

\usepackage{uolthesis}
\usepackage{setspace}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{alltt}
\usepackage{anysize}
\usepackage{appendix}
\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{changepage}
% \usepackage{cite}
\usepackage{color}
\usepackage{enumerate}
\usepackage{etoolbox}
\usepackage{fancyhdr}
\usepackage{fixltx2e}
\usepackage{footmisc}
% \usepackage{graphics}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{pdflscape}
\usepackage{ragged2e}
\usepackage{hyperref}
\usepackage{bookmark}
\usepackage[numbers,sort]{natbib}
% \usepackage{tocbibind}
\usepackage{url}

\marginsize{2.54cm}{2.54cm}{2.54cm}{2.54cm}

% LIST OF ABBREVIATIONS. ---------------------------------------------------------------------------------------

\usepackage[acronym,footnote,nonumberlist]{glossaries} % Makes a list of abbreviations.
\usepackage{glossary-mcols}

\renewcommand{\glossarypreamble}{Text to go here\ldots}

% LIST OF ABBREVIATIONS. --------------------------------------------------------------------------

% NOTE: The LaTeX glossary is in file Abbreviations.tex. The thesis glossary is in file Glossary.tex.

% With thanks to: http://tex.stackexchange.com/questions/197692/adding-a-specific-title-to-
%                 list-of-abbreviations-acronyms-in-latex.

\usepackage[acronym,footnote,nonumberlist]{glossaries} % Makes a list of abbreviations.
\usepackage{glossary-mcols}
% \makeglossaries % This must be run from the command-line: e.g. 'makeglossaries file'
                  % where `file` is the name of the main LaTeX file.
\renewcommand{\glossarypreamble}{Some text\ldots}

\include{DummyGlossary}
% \renewcommand{\glsnamefont}[1]{\textbf{#1}}

\makeglossaries
\glossarystyle{mcolindex}
% \glossarystyle{long}

% PART, CHAPTER AND SECTION NUMBERING.  -----------------------------------------------------------------------------------------------------------------

\makeatletter

\let\LaTeXStandardPart\part%
\newcommand{\unstarredpart@@noopt}[1]{%
    \unstarredpart@@opt[#1]{#1}%
}

\newcommand{\unstarredpart@@opt}[2][]{%
    \cleardoublepage% (For clearing content before.)
    \begingroup%
    \let\newpage\relax%
    \LaTeXStandardPart[#1]{#2}%
    \endgroup%
}

\newcommand{\starredpart}[1]{%
    \LaTeXStandardPart*{#1}%
}

\newcommand{\unstarredpart}{%
    \@ifnextchar[{\unstarredpart@@opt}{\unstarredpart@@noopt}%
}

\renewcommand{\part}{%
  \@ifstar{\starredpart}{\unstarredpart}%
}

% BIBLIOGRAPHY PREAMBLE. --------------------------------------------------------------------------

\renewcommand{\bibpreamble}{The references below are listed in order of author(s).}

% BEGIN DOCUMENT. ---------------------------------------------------------------------------------

\begin{document}

    \pagenumbering{roman}

    % Title page.
    \title{\textcolor{red}{** WORKING DRAFT **}}
    \author{Author}

    \begin{abstract}
        This report\ldots
    \end{abstract}

    % LISTINGS. ---------------------------------------------------------------------------------------

    \tableofcontents

    % Print glossary.
    \glsaddall
    \printglossary[type=acronym,title={List of Abbreviations}]\addcontentsline{toc}{chapter}{List of Abbreviations}    
    \printglossaries%[title={List of abbreviations}]

    % Print algorithms. 
    \clearpage% or \clearpage under the oneside option
    \phantomsection% Mark a hyperref link location
    \addcontentsline{toc}{chapter}{List of Algorithms}% Add contents entry for List of Tables
    \listofalgorithms% Start List of Tables
    \setcounter{chapter}{0}

    % Print figures.    
    \clearpage% or \clearpage under the oneside option
    \phantomsection% Mark a hyperref link location
    \addcontentsline{toc}{chapter}{List of Figures}% Add contents entry for List of Tables
    \listoffigures% Start List of Tables

    % Print tables.           
    \clearpage% or \clearpage under the oneside option
    \phantomsection% Mark a hyperref link location
    \addcontentsline{toc}{chapter}{List of Tables}% Add contents entry for List of Tables
    \listoftables% Start List of Tables

    \pagenumbering{arabic}

    \chapter{Introduction}

    Some text for the second reference \cite{Date}.

    \noindent Some text for the first reference \cite{Abiteboul_et_al}.

    \noindent Some text for the first reference \cite{Paass_et_al}.

    \noindent Abbreviations W3C and WWW.

    \chapter{Background}
    \chapter{Review}

    \part{Case study one}
    \chapter{Apparatus}
    \chapter{Method}
    \chapter{Experiment}
    \chapter{Results}

    \part{Case study two}
    \chapter{Apparatus}
    \chapter{Method}
    \chapter{Experiment}
    \chapter{Results}

    \appendix

    % Print figures.
    \clearpage% or \clearpage under the oneside option
    \phantomsection% Mark a hyperref link location
    \addcontentsline{toc}{chapter}{Bibliography}% Add contents entry for List of Tables
    \bibliography{DummyBibliography}
    \bibliographystyle{plain}



\end{document}

And bibliography:

@book{Abiteboul_et_al,
  author = {S. Abiteboul and P. Buneman and D. Suciu},
  title = {Data on the web: From relations to semi-structured data and XML},
  publisher = {Morgan-Kaufmann},
  address = {San Francisco, CA, USA},
  year = {2000}
}

@book{Date,
  author    = {C. J. Date},
  title     = {{An Introduction to Database Systems, 6th Edition}},
  publisher = {Addison-Wesley},
  year      = {1995},
  isbn      = {0-201-82458-2},
  timestamp = {Thu, 03 Jan 2002 11:51:07 +0100},
  biburl    = {http://dblp.uni-trier.de/rec/bib/books/aw/Date95},
  bibsource = {dblp computer science bibliography, http://dblp.org
}

@inproceedings{Paass_et_al,
  author    = {Gerhard Paa\ss and
               Edda Leopold and
               Martha Larson and
               J{\"{o}}rg Kindermann and
               Stefan Eickeler},
  title     = {{SVM Classification Using Sequences of Phonemes and Syllables}},
  booktitle = {Principles of Data Mining and Knowledge Discovery, 6th European Conference,
               {PKDD} 2002, Helsinki, Finland, August 19-23, 2002, Proceedings},
  year      = {2002},
  pages     = {373--384},
  crossref  = {DBLP:conf/pkdd/2002},
  url       = {http://dx.doi.org/10.1007/3-540-45681-3_31},
  doi       = {10.1007/3-540-45681-3_31},
  timestamp = {Fri, 12 Sep 2014 20:22:12 +0200},
  biburl    = {http://dblp.uni-trier.de/rec/bib/conf/pkdd/PaassLLKE02},
  bibsource = {dblp computer science bibliography, http://dblp.org}
}
6
  • Add \addcontentsline after \listof...
    – Sigur
    Commented Jan 6, 2015 at 0:59
  • Should I retain the \addcontentsline{toc}{chapter}{List of Figures} lines?
    – Mr Morgan
    Commented Jan 6, 2015 at 1:01
  • \listoftables\addcontentsline{toc}{chapter}{\listtablename}
    – Sigur
    Commented Jan 6, 2015 at 1:03
  • Try with \cleardoublepage\phantomsection\addcontentsline{toc}{\listtablename}\listoftables...
    – Werner
    Commented Jan 6, 2015 at 1:06
  • @Sigur: This works in the general case but happens in the case of my glossary code, i.e. \glsaddall \printglossary[type=acronym,title={List of Abbreviations}] \addcontentsline{toc}{chapter}{List of Abbreviations} And how might it be added to bibliography code?
    – Mr Morgan
    Commented Jan 6, 2015 at 1:11

1 Answer 1

2

You need to be on the correct page before you can issue contents-related macros. For this use

\cleardoublepage% or \clearpage under the oneside option
\phantomsection% Mark a hyperref link location
\addcontentsline{toc}{chapter}{\listtablename}% Add contents entry for List of Tables
\listoftables% Start List of Tables

One would do something similar for the ToC, the LoF and whichever other \chapter-related entry that is not in the ToC already.

If you want all list-of elements added to the ToC, you can also just add the tocbibind package to your preamble.

2
  • I am using tocbibind, but I get the Contents in the TOC, and am uncertain about how to apply tocbibind to the lists of algorithms and abbreviations. The other two lists appear to work.
    – Mr Morgan
    Commented Jan 6, 2015 at 1:36
  • @MrMorgan: Your example code doesn't show the use of tocbibind. Regardless, in order to get the other lists in the ToC, use my manual suggestion in the answer.
    – Werner
    Commented Jan 6, 2015 at 1:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .