Beginning latex user here,
I'm trying to customise a TOC using titletoc. What would like to align the parts and chapters so that the chapter/part names (e.g. Chapter 1, Part I) are right-aligned, whereas the titles of the chapters and parts should be left-aligned. Basically creating a gap between the names and titles that is exactly the same for chapters and parts.
I can think of possible solutions but cannot wrap my head around whether they work, and if so how to implement them:
- Put the Part X and Chapter X in a text-box of predefined with and align these. Problem with this is how to separate the chapter/part title from the chapter/part name?
- Increase the space between part name and chapter name. Problem with this is that this will not left-align chapter/part names.
I would really like to keep using titletoc because of its integration with titlesec, and I hope this is possible.
Thank you in advance for any ideas!
\documentclass{book}
\usepackage[newparttoc]{titlesec}
\usepackage{titletoc}
\titleformat{\part}
[display]
{\centering\bfseries\Huge}
{\huge\partname~\thepart}
{2ex}
{}
\contentsmargin[2.5cm]{-30pt}
\titlecontents{part}
[0em]
{\normalfont\vspace{1.5em}}
{{\partname~\thecontentslabel~\quad}}
{}
{}
[\titlerule\addvspace{.25em}]
\titlecontents{chapter}
[0em]
{\normalfont\filright}
{\contentsmargin{0pt}\contentspush{\bfseries\chaptername~\thecontentslabel~\quad}}
{}
{\hfill\thecontentspage}
[\addvspace{0.25em}]
\begin{document}
\tableofcontents
\part{First Part}
\chapter{Introduction}
\chapter{This is a chapter with a very long title that will go the the second row}
\part{Very important second part}
\chapter{Another introduction}
\end{document}