# Conflict between titlesec and xpatch

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}{%
}{%
}{}{}
\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
}\par\hfill\textsc{--- Some girl}}
\part{beta}
\chapter{three}
\lipsum
\chapter{four}
\lipsum

\end{document}

• Why don't you use the facilities of titletoc since you load titlesec? – Bernard Sep 4 '17 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. – user1844282 Sep 4 '17 at 1:32
• 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 – Ulrike Fischer Sep 4 '17 at 8:21

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}%
}

% 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}

\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}


• 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. – user1844282 Sep 5 '17 at 1:51