如何修改 \titlecontents{part}?

如何修改 \titlecontents{part}?

目前,我已经

在此处输入图片描述

我想改变零件条目来获得类似的东西

在此处输入图片描述

你能帮我修改下面的代码吗?


\documentclass{book}

\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern} 
\usepackage{titletoc}

\titlecontents{part}[0pt]{\normalsize\bfseries\protect\addvspace{15pt}}%
{}{\partname{} }%
{\enspace\titlerule\contentspage}%

\begin{document}

\tableofcontents

\part{This is the title of part 1}
\chapter{Chapter 1}
\section{Section 1.1}
\section{Section 1.2}

\end{document}

答案1

这是一个解决方案——但并不完美:对于编号部分,您不能有多个标题,因为我使用了包\brlap中的命令stackengine

\documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage[english]{babel}

\usepackage{etoolbox}
\usepackage[pagestyles ,newparttoc, explicit]{titlesec}%
\usepackage{titletoc}
\usepackage{stackengine}

\titleformat{name=\part}[display]{\filcenter\bfseries\boldmath\sffamily\Huge}{\partname~\Roman{part}}{\baselineskip}{#1}%
\titleformat{name=\part, numberless}[block]{\filcenter\bfseries\boldmath\sffamily\Huge}{}{0pt}{\raggedright#1}%

\newbool{numbered}
\titlecontents{part}[0em]{\large\sffamily\protect\addvspace{15pt}}%
{\global\booltrue{numbered}\contentslabel[{\partname\enspace\thecontentslabel}]{0em}\brlap[1.25\baselineskip]}{\global\boolfalse{numbered}}%
{\ifbool{numbered}{\hphantom{\partname\ \thecontentslabel\enspace}}{}\titlerule\contentspage}%

\begin{document}

\tableofcontents

\part{This is the title of part 1. }

\chapter{Chapter 1}
\section{Section 1.1}
\section{Section 1.2}

\part*{And now for the very different title of an unnumbered part. This is indeed quite a very very long title. }

\end{document}

在此处输入图片描述

相关内容