fancyhdr 书籍前言中的字母章节问题

fancyhdr 书籍前言中的字母章节问题

下面是一个不太一样的 MWE:

\documentclass{book}
\usepackage{a4wide}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{polyglossia}
\setmainlanguage[spelling=new,babelshorthands=true]{german}
\usepackage[autostyle]{csquotes}
\usepackage{lipsum}
\usepackage[style=authortitle-icomp,backref=true,backrefstyle=two+,hyperref=true,isbn=false,backend=biber,citereset=chapter,bibencoding=utf8]{biblatex}


\defbibheading{caption}{
    \phantomsection
    \addcontentsline{toc}{section}{#1}
    \section*{#1}%
    \markboth{#1}{#1}
}
\pagestyle{fancyplain}
\renewcommand{\chaptermark}[1]%
{\markboth{\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]%
{\markright{\thesection\ #1}}
\lhead[\fancyplain{}{\bfseries\thepage}]%
{\fancyplain{}{\bfseries\rightmark}}
\rhead[\fancyplain{}{\bfseries\leftmark}]%
{\fancyplain{}{\bfseries\thepage}}
\cfoot{}

\renewcommand\thechapter{\Alph{chapter}}

\begin{document}
\frontmatter
\tableofcontents
\chapter{First Chapter}
\lipsum[1-10]
\mainmatter
\chapter{Second Chapter}

\end{document}

我的问题:我想要按字母顺序对章节进行编号,这就是我使用的原因\renewcommand\thechapter{\Alph{chapter}}。但是对于第一章,它在前言中,编号为 0,没有字符,因此它只打印:

在此处输入图片描述

我想删除.前言中第一章之前的。我该怎么做?请注意,我\chaptermark在序言中重新定义了。我只需要\if...在那里有正确的陈述。有人能帮忙吗?

干杯

答案1

可以检查章节编号\markboth

\ifnum\value{chapter} = 0 \thechapter\else\thechapter.\fi

\documentclass{book}
\usepackage{a4wide}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{polyglossia}
\setmainlanguage[spelling=new,babelshorthands=true]{german}
\usepackage[autostyle]{csquotes}
\usepackage{lipsum}
\usepackage[style=authortitle-icomp,backref=true,backrefstyle=two+,hyperref=true,isbn=false,backend=biber,citereset=chapter,bibencoding=utf8]{biblatex}


\defbibheading{caption}{
    \phantomsection
    \addcontentsline{toc}{section}{#1}
    \section*{#1}%
    \markboth{#1}{#1}
}
\pagestyle{fancyplain}
\renewcommand{\chaptermark}[1]%
{\markboth{\ifnum\value{chapter} = 0 \thechapter\else\thechapter.\fi\ #1}{}}
\renewcommand{\sectionmark}[1]%
{\markright{\thesection\ #1}}
\lhead[\fancyplain{}{\bfseries\thepage}]%
{\fancyplain{}{\bfseries\rightmark}}
\rhead[\fancyplain{}{\bfseries\leftmark}]%
{\fancyplain{}{\bfseries\thepage}}
\cfoot{}

\renewcommand\thechapter{\Alph{chapter}}
% In case there is a section:
%\renewcommand{\thesection}{\ifnum\value{chapter} = 0 \arabic{section}\else \thechapter.\arabic{section}\fi}


\begin{document}

\frontmatter
\tableofcontents
\chapter{First Chapter}
\lipsum[1-10]
\mainmatter
\chapter{Second Chapter}

\lipsum[1-10]

\end{document}

相关内容