4

I am new to LaTeX and still on the steep learning curve. I am writing some documentation for a school project which has a bibliography and an index, using ShareLaTeX. I am having difficulty getting the index to show in the table of contents. This bare-bones code sample illustrates my problem.

\documentclass[a4paper]{report}

\usepackage{lipsum}
\usepackage{makeidx}

\makeindex
\begin{document}
\tableofcontents
\clearpage{\pagestyle{empty}\cleardoublepage}

\chapter{Introduction}
Some random \index{random} text \index{stuff!text} about fact \cite{fact}.
\clearpage{\pagestyle{empty}\cleardoublepage}

\chapter{Main}
\lipsum[6]
\clearpage{\pagestyle{empty}\cleardoublepage}

\addcontentsline{toc}{chapter}{Bibliography}
\begin{thebibliography}{9}
    \bibitem{fact}
    Factual stuff,
    \emph{The types of Facts}. \\
    XXXX, Publisher
    \end{thebibliography}
\clearpage{\pagestyle{empty}\cleardoublepage} %Line 1

\addcontentsline{toc}{chapter}{Index} %Line 2
\printindex
\clearpage{\pagestyle{empty}\cleardoublepage}

\end{document}

If I change Line 1 to \clearpage{\pagestyle{empty}} then the index shows up in the table of contents, however I want to ensure the index starts on an odd page. I have tried using the hyperref package but doing this with the package:

\phantomsection
\addcontentsline{toc}{chapter}{Index}
\printindex
\clearpage{\pagestyle{empty}\cleardoublepage}

seems to have no effect. I've been looking all over the internet for an answer and I haven't found it. I would appreciate any help and if you need more info please let me know I will do my best :-)

2
  • Welcome to TeX.SX. Do you want all chapters to start on odd pages? Commented Nov 11, 2013 at 21:56
  • Thank you. Yes I do, I'd also like the index to start on an odd page (as long as that does not break typesetting convention. Commented Nov 12, 2013 at 22:24

2 Answers 2

5

To have chapters start on odd pages, you can add twoside,openright to the options of the class. This will change the layout to fit twosided printing, and cause all chapters to start on a right/recto/odd pages.

To add bibliography and index to the ToC, you can add

\usepackage[nottoc]{tocbibind}

to the preamble. nottoc means that the ToC itself does not end up in the ToC.

Also, I just noticed that the index does not seem to start on an odd page even with twoside,openright, add a \cleardoublepage just before \printindex to take care of that. Complete code example:

\documentclass[a4paper,openright,twoside]{report}

\usepackage{lipsum}
\usepackage{makeidx}
\usepackage[nottoc]{tocbibind}

\makeindex
\begin{document}
\tableofcontents


\chapter{Introduction}
Some random \index{random} text \index{stuff!text} about fact \cite{fact}.


\chapter{Main}
\lipsum[6]



\begin{thebibliography}{9}
    \bibitem{fact}
    Factual stuff,
    \emph{The types of Facts}. \\
    XXXX, Publisher
    \end{thebibliography}

\cleardoublepage\printindex


\end{document}
8
  • First of all, thank you very much for the twoside, openright tip, that's very efficient. Secondly, when I tried the source code you provided in ShareLaTeX,the index did not show up in the ToC. Should I try another distribution of LaTeX (I have a portable version of MikTeX as a backup)? Commented Nov 12, 2013 at 22:27
  • 1
    @neoTexDalus Please try in MikTeX. It works fine for me with TeX Live 2013, while ShareLaTeX uses TeX Live 2011. I guess that there is something that has changed between the two versions. Commented Nov 12, 2013 at 22:46
  • @neoTexDalus By the way, I just noticed that the index does not start on an odd page even with twoside,openright, so add a \cleardoublepage just before \printindex to fix that (I've updated my answer.) Commented Nov 12, 2013 at 22:56
  • @ Torbjørn T. I tried it in TexLive 2013 (MikTex had some problem with missing fonts or something) and it worked just beautifully. I think maybe ShareLaTeX isn't doing either enough or misordered runs of pdfLaTeX, BibTex and MakeIndex. I'll keep using it and just compile using TexLive 2013 when I need to submit. As a note to you and others I found an emptypage package which combined with your suggestion is a more efficient way to get \clearpage{\pagestyle{empty}\cleardoublepage. Commented Nov 14, 2013 at 20:14
  • @TorbjørnT. When I added the tocbibind package as per above, it threw the following error: Option clash for package tocbibind.
    – SuperAl
    Commented Dec 14, 2019 at 17:57
-1

Add toc request when you make the index:

\makeindex[columns=3, title=Alphabetical Index, intoc]
1
  • 1
    What package is required that provides the intoc option to \makeindex? Ahhh, imakeidx. Why don't you include that in your answer?
    – Werner
    Commented Feb 3, 2022 at 17:01

You must log in to answer this question.

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