删除后记标题中的“章节”

删除后记标题中的“章节”

在我的附录中,标题显示为Chapter x: chapter-namex附录前最后一章的编号(或字母,如果我有附录)在哪里。我怎样才能让附录中的标题只显示出来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它们每个添加相应的重新定义。

相关内容