3

As part of my thesis, I am trying to create a final table of contents listing all the titles that appear in my thesis (the basic format suits me fine), but I also want to display a summary at the beginning, which is a simplified table of contents where only the \part, \chapter and \section found in the \mainmatter are displayed, nothing else.

I tried shorttoc, titletoc, minitoc, etc., with varying degrees of success, and never managed to remove what is in the \fontmatter or \backmatter (at least, without removing it from the toc at the same time).

If I understand correctly, minitoc only allows you to display toc at the beginning of each chapter, not at the start, and shorttoc doesn't really provide any options...

\documentclass[12pt, oneside]{book}

\begin{document}

\frontmatter
\chapter{Introduction}
%Here, the partial toc with all parts, chapters and sections that are in the mainmatter and only these%

\mainmatter
\part{Part 1}


\chapter{Chapter 1}
    \section{Section 1}
    \section{Section 2}
    
\part{Part 2}

\chapter{Chapter 2}
    \section{Section 1}
    \section{Section 2}

\backmatter

\chapter{Conclusion}

\tableofcontents %Which is perfect%

\end{document}

Please let me know which package would be able to do this and how!

3
  • 1
    Worst case you will need to create a second toc file (e.g. tocB) and add \addcontentsline commands to every \part, \chapter etc. Search \@starttoc. Commented Jul 17 at 21:20
  • 2
    The etoc package should meet your needs. Commented Jul 17 at 21:50
  • 2
    etoc definitely. the documentation is also extremely good (if a bit overwhelming.) Commented Jul 18 at 1:56

2 Answers 2

2

Here is a way using etoc. Observe the \etocdepthtag.toc commands used nearby \frontmatter, \mainmatter and \backmatter.

\documentclass[12pt, oneside]{book}
\usepackage{etoc}
\begin{document}

\frontmatter
\etocdepthtag.toc{front}
\chapter{Introduction}

%Here, the partial toc with all parts, chapters and sections that are in the mainmatter and only these%
\etocsettagdepth{front}{none}% front matter ignored
\etocsettagdepth{back}{none}%  back matter ignored
\etocsettagdepth{main}{section}% display part, chapter, section from main
\tableofcontents

\mainmatter
\etocdepthtag.toc{main}
\part{Part 1}


\chapter{Chapter 1}
    \section{Section 1}
    \section{Section 2}
    
\part{Part 2}

\chapter{Chapter 2}
    \section{Section 1}
    \section{Section 2}

\backmatter
\etocdepthtag.toc{back}

\chapter{Conclusion}

\etocignoredepthtags
\tableofcontents %Which is perfect%

\end{document}

toc via etoc

1
  • Thank you very much! Finally, I chose this solution over the other one because it caused problems with PDF bookmarks that were no longer displaying; with this solution, everything works fine! Commented Jul 23 at 18:03
4

etoc can do this and far more, but if you just want something simple, this may suffice:

\documentclass[12pt, oneside]{book}
% ateb: https://tex.stackexchange.com/a/748026/
\newif\ifbigtoc
\makeatletter
\AddToHook{begindocument/end}{%
  \addtocontents{toc}{\string\ifbigtoc}%
  \bigtocfalse
}
\AddToHook{cmd/mainmatter/before}{%
  \addtocontents{toc}{\string\fi}%
}
\AddToHookNext{cmd/tableofcontents/before}{%
  \@fileswfalse
  \AddToHookNext{cmd/tableofcontents/before}{%
    \@fileswtrue
  }%
}
\AddToHook{cmd/backmatter/before}{%
  \addtocontents{toc}{\string\ifbigtoc}%
  \bigtoctrue
}
\AddToHook{shipout/lastpage}{%
  \addtocontents{toc}{\string\fi}%
}
\makeatother

\begin{document}
\frontmatter
\chapter{Introduction}
\tableofcontents

\mainmatter
\part{Part 1}

\chapter{Chapter 1}
\section{Section 1}
\section{Section 2}

\part{Part 2}

\chapter{Chapter 2}
\section{Section 1}
\section{Section 2}

\backmatter

\chapter{Conclusion}

\tableofcontents 

\end{document}

two tocs

1
  • Thanks, it worked just perfectly ! Commented Jul 19 at 10:28

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.