0

I apologise if this question is too specific.

I am trying to achieve centred 'part' titles in the toc (using xpatch) with a customised 'part-title-page' (using titlesec). I find that I cannot get these to work simultaneously.

I've put a MWE below in which I have achieved the centred part titles I want in the toc, but with standard part-title-pages. If I uncomment the block "Custom part-title-pages with epigraph", I get the look I want at the beginning of each part, but the toc has reverted to left aligned part titles.

I've tried switching the order of these blocks of code to no avail. Any suggestions would be greatly appreciated.

\documentclass[a4paper,12pt]{book}
\usepackage{lipsum} % lorum ipsum
\usepackage{titlesec}
\usepackage{epigraph} % quotes at the beginning of parts
\usepackage{xpatch} % used for patching part to allow multi-line centred part titles in toc.


% Centered Part titles in toc
\DeclareRobustCommand{\wrapmytitles}[1]{%
\leavevmode

\centering
\parbox{0.8\linewidth}{\centering #1}%

}
%
\makeatletter
\xpatchcmd{\@part}{%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
}{%
\addtocontents{toc}{\begingroup\vspace{5mm}\large \bfseries\scshape\protect\centering\underline{\partname\ \thepart}\par\vspace{-5mm}\large\bfseries\scshape\wrapmytitles{#1}\par\vspace{5mm}\endgroup}
}{}{}
\makeatother

% Custom part-title-pages with epigraph
%\titleclass{\part}{top} 
%\titleformat{\part}
%[display]
%{\centering\Huge\bfseries}{\titlerule[5pt]\vspace{3pt}\titlerule[2pt]\vspace{3pt}\MakeUppercase{\partname} \thepart}
%{0pt}
%{\titlerule[2pt]\vspace{1pc}\huge\MakeUppercase}
%[\vspace{2ex}\titlerule {\thispagestyle{epigraph}}\vspace{10cm}]
%\titlespacing*{\part}{0pt}{0pt}{0pt}
%\setlength\epigraphwidth{.9\textwidth}
%\renewcommand{\epigraphflush}{center}

\begin{document}

\title{Minimum not-working example}

\frontmatter
\maketitle
\tableofcontents

\mainmatter

\epigraphhead[450]{\centering \it{A truly awe-inspiring quote}\par\hfill\textsc{--- Some guy}}
\part{alpha}
\chapter{one}
\lipsum
\chapter{two}
\lipsum
\pagebreak
\epigraphhead[450]{\centering \it{Another great quote 
}\par\hfill\textsc{--- Some girl}}
\part{beta}
\chapter{three}
\lipsum
\chapter{four}
\lipsum

\end{document}
3
  • 1
    Why don't you use the facilities of titletoc since you load titlesec?
    – Bernard
    Commented Sep 4, 2017 at 0:12
  • I'd love to, but I couldn't find a way to achieve the toc style I want: part titles: centred with no page number, part # underlined, title on newline, everything else left aligned with page numbers, without using xpatch. Commented Sep 4, 2017 at 1:32
  • 1
    It won't work, titlesec redefines \part and it not longer uses internally \@part. Your patch is simply ignored. Use titletoc. You will need the newparttoc option to be able to manipulate the toc entry as you want it, see e.g. tex.stackexchange.com/a/276102/2388 Commented Sep 4, 2017 at 8:21

1 Answer 1

2

Here it is. I added some modifications: I don't see why you modified the class of \part to top since your parts are on a single page, so I removed it. Also, I think it's nicer to have no page number on part pages; for this I had to patch the \epigraphhead command. Should you prefer a page number, you'd only have to remove the patch.

\documentclass[a4paper,12pt]{book}
\usepackage{lipsum} % lorum ipsum
\usepackage[newparttoc, clearempty]{titlesec}
\usepackage{titletoc}
\usepackage{epigraph} % quotes at the beginning of parts
\usepackage{xpatch} % used for patching \epigraphhead to have the empty page style on part g3pages.


% Centered Part titles in toc
\DeclareRobustCommand{\wrapmytitles}[1]{%
\leavevmode

\centering
\parbox{0.8\linewidth}{\centering #1}%
}

\xpatchcmd{\epigraphhead}{\hfil\thepage\hfil}{}{}{}
% Custom part-title-pages with epigraph
\titleformat{\part}
[display]
{\centering\Huge\bfseries}{\titlerule[5pt]\vspace{3pt}\titlerule[2pt]\vspace{3pt}\MakeUppercase{\partname} \thepart}
{0pt}
{\titlerule[2pt]\vspace{1pc}\huge\MakeUppercase}
[\vspace{2ex}\titlerule {\thispagestyle{epigraph}}\vspace{10cm}]
\titlespacing*{\part}{0pt}{0pt}{0pt}
\setlength\epigraphwidth{.9\textwidth}
\renewcommand{\epigraphflush}{center}

\titlecontents{part}[0pt]{\addvspace{2pc}\centering\large\bfseries}{\partname~\thecontentslabel \endgraf}{}{}%

\begin{document}

\title{Minimum not-working example}

\frontmatter
\maketitle
\tableofcontents

\mainmatter

\epigraphhead[450]{\centering \it{A truly awe-inspiring quote}\par\hfill\textsc{--- Some guy}}
\part{Alpha}
\chapter{One}
\lipsum
\chapter{Two}
\lipsum
\pagebreak
\epigraphhead[450]{\centering \it{Another great quote}\par\hfill\textsc{--- Some girl}}
\part{Beta}
\chapter{Three}
\lipsum
\chapter{Four}
\lipsum

\end{document} 

enter image description here

1
  • This is exactly what I was after. It also works with multiple line part titles which I had difficulty getting to work using titletoc. Much appreciated. Commented Sep 5, 2017 at 1:51

You must log in to answer this question.

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