[Tex/LaTex] How to add abstract to table of contents

abstracttable of contents

I believe it is correct to add the abstract to my TOC but I don't know how. This Answer talking about adding the abstract chapter to the TOC. I'm using Lyx and if I output to .tex file this is what I see.

\documentclass[english]{report}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{babel}

\makeatother

\usepackage{babel}
\begin{document}

\title{My Title}


\author{My Name}

\maketitle
\tableofcontents{}
\begin{abstract} %% This isn't a chapter!

My Abstract isn't a chapter.


Abstract is created with begin{abstract} unlike in questions I LINKED to and have been marked as a duplicate. In that example abstract is a chapter.
Does this affect the correct use of getting my Abstract into the TOC?


Assuming that the abstract and acknowledgement contents is typeset using a \chapter*{…},

Well it isn't, So what do I do in my case?

Best Answer

Within report, the abstract environment is set using within a titlepage, which defaults to putting the content on its own page. So you have to insert the ToC-writing piece using some patching (supported via etoolbox).

enter image description here

\documentclass{report}
\usepackage[paper=a6paper]{geometry}% Just for this example
\usepackage{lipsum,etoolbox}% http://ctan.org/pkg/{lipsum,etoolbox}

% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\abstract}{\titlepage}{\titlepage% Insert ToC-writing after starting a titlepage
  \addcontentsline{toc}{chapter}{Abstract}}{}{}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\begin{document}

\title{My Title}

\author{My Name}

\maketitle

\tableofcontents

\begin{abstract}
\lipsum[1]
\end{abstract}

\chapter{A chapter}

\end{document}

I've written the ToC-entry as a chapter, just so the formatting seems consistent

\addcontentsline{toc}{chapter}{Abstract}

However, that can be changed to whatever you like.


Another way would be to write the ToC-entry within the abstract environment - this ensures that it falls on the same page as the Abstract:

\begin{abstract}
  \addcontentsline{toc}{chapter}{Abstract}
  ...
\end{abstract}
Related Question