我不知道为什么!为什么在我的例子中,第一章可以,而第二章在页面上的位置较高?
\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[top=2cm, bottom=2cm, left=1.5cm, right=1.5cm, headheight=15pt]{geometry}
\usepackage{fancyhdr}
\usepackage{microtype}
\usepackage[x11names]{xcolor}
\usepackage{tabularx}
\usepackage{colortbl}
\usepackage{titlesec}
%%%%%%%%%%%%%%%
\colorlet{titlecolour}{Aquamarine3}
\newlength\labelframewd
\settowidth{\labelframewd}{\lsstyle\scshape\small\MakeLowercase{\chaptername}}
\newsavebox\chaplabelbox%
\newcommand\chaplabel{\color{titlecolour}%
\begin{tabularx}{\linewidth}{c@{\enspace}X}
\lsstyle\scshape\small\MakeLowercase{\chaptername}\\
\cellcolor{titlecolour}\raisebox{-1ex}[5ex][20ex]{\color{black}\bfseries\fontsize{36}{40}\selectfont\thechapter} & \titlerule[2pt]
\end{tabularx}
}%
\titleformat{\chapter}[display]{\centering}
{\setlength{\tabcolsep}{0pt} \smash{\chaplabel}}%
{2ex}
{\thispagestyle{fancy}\vskip-10ex\hskip\labelframewd\fontsize{28}{32}\selectfont\bfseries}%
\titlespacing{\chapter}{0pt}{1.8\baselineskip}{10\baselineskip}
\renewcommand\thechapter{\arabic{chapter}}
%%%%%%%%%%%%%%%
\makeatletter
\renewcommand\part{%
\thispagestyle{fancy}%
\if@twocolumn
\onecolumn
\@tempswatrue
\else
\@tempswafalse
\fi
\null\vfil
\secdef\@part\@spart}
\renewcommand\chapter{
\thispagestyle{fancy}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter}
\makeatother
%%%%%%%%%%%%%%
\begin{document}
\chapter{Test}
\pagebreak
\chapter{Nice Chapter}
\pagebreak
\end{document}
警告:
LaTeX Font Warning: Font shape `OT1/cmr/m/n' in size <28> not
available (Font) size <24.88> substituted on input line 61.
LaTeX Font Warning: Font shape `OT1/cmr/bx/n' in size <28> not
available (Font) size <24.88> substituted on input line 61.
LaTeX Font Warning: Size substitutions with differences (Font) up
11.12pt have occurred.
答案1
罪魁祸首是您对 的重新定义\chapter
– 它干扰了通过 进行的重新定义titlesec
。此外,我不明白您想要在章节的第一页上使用花哨的页面样式:在包含该章节标题的页面的页眉中显示章节标题有什么用?
一般来说,如果您使用titlesec
,则通过包进行所有重新定义(对于也是如此part
)。
下面是我注释掉重新定义的结果\chapter
。我认为,如果没有标题规则,效果会更好。
\renewcommand\chapter{
\thispagestyle{fancy}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter}