![如何修复新章节之前出现的章节标题?](https://linux22.com/image/462585/%E5%A6%82%E4%BD%95%E4%BF%AE%E5%A4%8D%E6%96%B0%E7%AB%A0%E8%8A%82%E4%B9%8B%E5%89%8D%E5%87%BA%E7%8E%B0%E7%9A%84%E7%AB%A0%E8%8A%82%E6%A0%87%E9%A2%98%EF%BC%9F.png)
我为每个章节设置了一个标题页,但我不明白为什么章节标题会出现在章节之前。
\documentclass[12pt, oneside]{book}
\usepackage{fancyhdr}
\renewcommand{\chaptermark}[1]{\markboth{#1}{#1}}
\fancyhead[L]{}
\fancyhead[R]{\chaptername\ \thechapter\ --\ \leftmark}
\fancyfoot{}
\fancyfoot[R]{\thepage}
\renewcommand{\headrulewidth}{1pt}
\mainmatter
\titleclass{\chapter}{page}
\assignpagestyle{\chapter}{empty}
\titleformat{\chapter}
[display]
{\centering\Huge\bfseries}
{\chaptertitlename{}\ \thechapter}
{0pt}
{\huge}
[\clearpage]
\begin{document}
\pagestyle{fancy}
\input{chapters/chapter1}
\input{chapters/chapter2}
\input{chapters/chapter3}
\input{chapters/chapter4}
\input{chapters/chapter5}
\input{chapters/chapter6}
\end{document}
答案1
此代码使用了explicit
的参数titlesec
,以便\chapter
在使用章节标题时可以使用的格式设置来设置左边的标记。
该命令\renewcommand{\chaptermark}[1]{...
将左标记格式化为破折号。
\documentclass[12pt, oneside]{book}
\usepackage[explicit]{titlesec}% changed <<<<
\titleclass{\chapter}{page}
\assignpagestyle{\chapter}{empty}
\titleformat{\chapter}
[display]
{\centering\Huge\bfseries}
{\chaptertitlename{}\ \thechapter}
{0pt}
{\huge}
[#1\markboth{#1}{}\clearpage]% changed <<<<<<<<<<<<
\usepackage{fancyhdr}
\setlength{\headheight}{15pt}
\fancypagestyle{fancy}{%
\fancyhf{}
\fancyhead[R]{\nouppercase\leftmark}% changed <<<<<<<<<<
\fancyfoot[R]{\thepage}
\renewcommand{\headrulewidth}{1pt}
}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{% format the left mark <<<<
\markboth{\normalfont\sffamily\chaptername\ \thechapter\ -- #1}{}}
\usepackage{kantlipsum}% only dummy text
\begin{document}
\mainmatter% in here <<<<<<<<<<<<<<
\chapter{The First}
\kant[1-4]
\chapter{The Second}
\kant[1-4]
\chapter{Behavior, HPA Axis and Hormones}
\kant[1-4]
\chapter{GABA\textsubscript{A} Receptor Subunit Expression}
\section{Introduction}
\kant[1-4]
\end{document}