我希望 \part 标题如图 1 所示,居中显示在两行,但我无法创建正确的代码,即使我在 titletoc 手册中没有找到针对 \part 的具体处理方法。
下面的代码
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{titletoc}
\titlecontents{part}
[0em]
{\addvspace{1.5pc}\filcenter}
{\thecontentslabel* \huge}
{\huge}
{} % without page number
[\addvspace{.5pc}]
\begin{document}
\tableofcontents
\part{Something as a title}
\end{document}
没有产生我想要的结果。但我不确定 titletoc 句柄是否完全\part...谢谢!
答案1
book
titletoc
与原样不兼容。使用补丁此处提出您可以轻松地让它工作:
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{titletoc}
% book -- titletoc patch: https://tex.stackexchange.com/a/454553/134574
\usepackage{etoolbox}
\makeatletter
\patchcmd\@part
{\thepart}
{\protect\numberline{\thepart}}
{}{\FAIL}
\makeatother
\titlecontents{part}
[0em]
{\addvspace{1.5pc}\filcenter}
{\large\partname~\thecontentslabel\endgraf\bfseries}
{\large}
{} % without page number
[\addvspace{.5pc}]
\begin{document}
\tableofcontents
\part{Something as a title}
\end{document}
答案2
像这样?
\documentclass{book}
\usepackage[newparttoc]{titlesec}
\usepackage{titletoc} %
\titleformat{\part}[display]
{\Huge\scshape\filright\centering}
{}
{20pt}
{\thispagestyle{empty}}
\titlecontents{part}[0pt]{\addvspace{2pc}\centering\large}{\parbox[t][3ex][t]{\linewidth}{\centering\partname~\thecontentslabel} \bfseries}{}{}[\medskip]%
\begin{document}
\tableofcontents
\part{This is a part of a document}
\chapter{Chapter Title}
\end{document}