我使用以下代码来格式化章节标题
\usepackage{titlesec}
\titleformat{\chapter}[display]% command + shape
{%
\normalfont
\Large
\filcenter
\sffamily
} % format
{%
\vspace*{\fill}
\titlerule[1pt]%
\vspace{1pt}%
\titlerule
\vspace{1pc}%
\LARGE\MakeUppercase{\chaptertitlename}~\thechapter%
}% label
{
1pc
}% separation
{
\titlerule[3pt]
\Huge
} % before
[%
\vspace*{\fill}
\thispagestyle{empty}
\clearpage
\addtocounter{page}{-1}
]% after
它还格式化了目录和图片列表的标题。我不希望将此格式应用于目录和图片列表标题。我该怎么做?
答案1
您需要添加代码来表示numberless
品种。如下所示:
\documentclass[oneside]{book}
\usepackage{titlesec}
\titleformat{name=\chapter}[display]% command + shape
{\normalfont\Large\sffamily\filcenter} % format
{\vspace*{\fill}\titlerule[1pt]\vspace{1pt}\titlerule\vspace{1pc}%
\LARGE\MakeUppercase{\chaptertitlename}~\thechapter}% label
{1pc}% separation
{\titlerule[3pt]\Huge} % before
[\vspace*{\fill}\thispagestyle{empty}\clearpage\addtocounter{page}{-1}]% after
\titleformat{name=\chapter,numberless}[display]
{\normalfont\Huge\sffamily\filcenter}
{}
{0pt}
{}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Test}
This is the text of the chapter.
\end{document}
说实话,我不太喜欢这个。也许“第 1 章”部分应该更高,标题应该比它远得多,并占据页面的垂直中心。
在我看来,抑制页码不是一个好主意。
答案2
只需使用tocloft
以常规格式设置 ToC 等标题的包。
% toctitleprob.tex SE 577538
\documentclass{report}
\usepackage{tocloft} %%%% new
\usepackage{titlesec}
\titleformat{\chapter}[display]% command + shape
{%
\normalfont
\Large
\filcenter
\sffamily
} % format
{%
\vspace*{\fill}
\titlerule[1pt]%
\vspace{1pt}%
\titlerule
\vspace{1pc}%
\LARGE\MakeUppercase{\chaptertitlename}~\thechapter%
}% label
{
1pc
}% separation
{
\titlerule[3pt]
\Huge
} % before
[%
\vspace*{\fill}
\thispagestyle{empty}
\clearpage
\addtocounter{page}{-1}
]% after
\begin{document}
\tableofcontents
\chapter{First}
\end{document}