![删除后记标题中的“章节”](https://linux22.com/image/279392/%E5%88%A0%E9%99%A4%E5%90%8E%E8%AE%B0%E6%A0%87%E9%A2%98%E4%B8%AD%E7%9A%84%E2%80%9C%E7%AB%A0%E8%8A%82%E2%80%9D.png)
在我的附录中,标题显示为Chapter x: chapter-name
,x
附录前最后一章的编号(或字母,如果我有附录)在哪里。我怎样才能让附录中的标题只显示出来chapter-name
?我已经chaptermark
根据这个修改了解决方案使其不在前页的页眉中出现Chapter 0
(删除它不会影响后页的页眉)。我该如何调整它以使其不在Chapter x
页眉中出现?
\documentclass[a4paper,11pt,twoside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\renewcommand{\chaptermark}[1]{%
\ifnum\value{chapter}>0
\markboth{Chapter \thechapter{}: #1}{}%
\else
\markboth{#1}{}%
\fi}
\begin{document}
\frontmatter
\chapter{abstract}
some text
\mainmatter
\chapter{some chapter}
some text
\appendix
\chapter{some appendix}
some text
\backmatter
\chapter{some backmatter}
some text
\newpage
some text
\newpage
some text
\end{document}
答案1
您使用了错误的条件:
\documentclass[a4paper,11pt,twoside]{book}
\usepackage{lipsum} % just for the example
\usepackage{fancyhdr}
\pagestyle{fancy}
\setlength{\headheight}{13.6pt} % as requested by fancyhdr's warning
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\makeatletter
\renewcommand{\chaptermark}[1]{%
\if@mainmatter
\markboth{Chapter \thechapter{}: #1}{}%
\else
\markboth{#1}{}%
\fi
}
\makeatother
\begin{document}
\frontmatter
\chapter{abstract}
\lipsum[1]
\mainmatter
\chapter{some chapter}
\lipsum[1-20]
\appendix
\chapter{some appendix}
\lipsum[1-20]
\backmatter
\chapter{some backmatter}
\lipsum[1-20]
\end{document}
在前文和后文中,条件均\if@mainmatter
设置为 false。
答案2
如果您所寻找的是\chaptermark
根据您位于文档的“前面”、“主要”还是“后面”部分而以不同的方式进行定义,您可以修改\frontmatter
,\mainmatter
然后\backmatter
他们会为您进行如下更改:
\documentclass[a4paper,11pt,twoside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\makeatletter
\g@addto@macro{\frontmatter}{
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}%
}
}
\g@addto@macro{\mainmatter}{
\renewcommand{\chaptermark}[1]{%
\markboth{Chapter \thechapter{}: #1}{}%
}
}
\g@addto@macro{\backmatter}{
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}%
}
}
\makeatother
\begin{document}
\frontmatter
\chapter{abstract}
some text
\mainmatter
\chapter{some chapter}
some text
\appendix
\chapter{some appendix}
some text
\backmatter
\chapter{some backmatter}
some text
\newpage
some text
\newpage
some text
\end{document}
宏\g@addto@macro
将一些代码附加到宏的定义中;我在这里使用它为\chaptermark
它们每个添加相应的重新定义。