2

I have the chapters of my text (report class) ideally divided in two main groups: FIRST PART and SECOND PART. Inside the text, right before the first chapter of each part is displayed, I created an isolated page like this:

\clearpage
\thispagestyle{empty}
\null\vspace{\stretch{1}}
\begin{center}
{\Huge FIRST/SECOND PART}\\
\par\vspace{0.7cm}\noindent
{\Large\textit{First/Second Part Description}}
\end{center}
\vspace{\stretch{2}}\null

I would like to have this division of the text in two parts reflected inside the ToC by having "FIRST/SECOND PART // First/Second Part" Description" appear centered (and maybe bold) right before the first chapter of the first/second part in the ToC, without the page number displayed but maybe with an hyperref to that page (if that's easy, it's not essential).

I have no clue on how to achieve that and any help would be much appreciated!

  • Even inserting the part division by hand in the ToC would be fine, if any other solution is not easily adoptable. But, again, no idea on how to "insert" random text inside a ToC! – lucia de finetti Apr 11 '17 at 22:14
  • there are two commands that will insert material into the .toc file to be added to the contents list. \addcontentsline is usually what is wanted when a page number is also wanted, and \addtocontents when no page number is to appear. i'm sure this question has been asked before. this question might help: How to add a line to the Table of Contents without a page number but if it doesn't, there are others. – barbara beeton Apr 12 '17 at 1:06
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – user36296 Oct 24 '18 at 21:29
2

This uses the code fragment about the part dividers (why not using \part?) and adds a hypertarget to the relevant page and a centered ToC line which links to the page.

\documentclass{report}

\usepackage{blindtext}

\newcounter{dummypart}

\usepackage{hyperref}

\makeatletter
\newcommand{\partdivider}[2]{%
  \clearpage
  \thispagestyle{empty}
  \null\vspace{\stretch{1}}
  \begin{center}
    {\Huge #1}

    \vspace{0.7cm}\noindent
    {%
      \refstepcounter{dummypart}%
      \label{dummypart:\thedummypart}%
      \hypertarget{dummypart:\thedummypart}{\Large\textit{#2}}%
    }
  \end{center}
  %Need \protect to prevent breaking of commands during write process to the .aux file!
  \addtocontents{toc}{\protect\centering\protect\hyperlink{dummypart:\thedummypart}{\textit{#2}}\protect\par}
  \vspace{\stretch{2}}\null%
}
\makeatother


\begin{document}
\tableofcontents


\partdivider{First Part}{The Fellowship Of The Ring}

\chapter{Foo}


\partdivider{Second Part}{The Two Towers}

\chapter{Foobar}




\partdivider{Third Part}{The Return Of The King}

\chapter{Other Foobar}


\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.