\documentclass[twoside,11pt]{book}
\usepackage{fancyhdr,xcolor,lipsum}
\let\Chaptermark\chaptermark
\def\chaptermark#1{\def\Chaptername{#1}\Chaptermark{#1}}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
\colorlet{myfancycolor}{black}
\fancypagestyle{mystyle}{
\renewcommand*\footrulewidth{1pt}
\fancyfoot[OR]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hfil
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
\fancyfoot[OL]{%
\Chaptername
}
\fancyfoot[EL]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
\fancyfoot[ER]{%
\rightmark{
\footnotesize\textbf{INTRODUCTION TO MATLAB}
}
}
}
\pagestyle{mystyle}
\begin{document}
\frontmatter
\chapter{PREFACE}
\lipsum[1-5]
\tableofcontents
\mainmatter
\chapter{LALALA LALALA LALALA}
\lipsum[1-8]
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\end{document}
我在制作页脚时遇到问题。在\mainmatter
没有问题。在\frontmatter
有问题。
我想要偶数页的页脚是书名(带页码),奇数页的页脚是章节名称(带页码)。结果\mainmatter
没有问题。但是在\frontmatter
,如果我制作章节前言,目录的页脚(在奇数页)是“前言”。此外,在偶数页中,会显示“目录”和书名。(见上面的图片)
为什么设置fancyhdr
跟设置的不一致呢\mainmatter
?
如何使 的设置与fancyhdr
的\frontmatter
设置相同\mainmatter
?
附录:
\documentclass[twoside,11pt]{book}
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm,papersize={15.5cm,23.5cm}]{geometry}
\usepackage{fancyhdr,lipsum,xcolor,hyperref}
\let\Chaptermark\chaptermark
\def\chaptermark#1{\def\Chaptername{#1}\Chaptermark{#1}}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
\colorlet{myfancycolor}{black}
\fancypagestyle{mystyle}{
%\renewcommand*\footrulewidth{1pt}
\fancyfoot[OR]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hfil
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
\fancyfoot[OL]{%
\footnotesize\textbf{\nouppercase{\Chaptername}}%
}
\fancyfoot[EL]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
\fancyfoot[ER]{%
\footnotesize\textbf{INTRODUCTION TO MATLAB}%
}
}
\fancypagestyle{frontmatter}[mystyle]{
\fancyfoot[OL]{%
\footnotesize\textbf{\nouppercase{\Chaptername}}%
}
}
\begin{document}
\frontmatter
\pagestyle{frontmatter}
\chapter{PREFACE}
\lipsum[1-20]
{%
\cleardoublepage
\newpage
\renewcommand{\Chaptername}{CONTENTS}
\phantomsection\addcontentsline{toc}{chapter}{CONTENTS}
\tableofcontents
}%
\mainmatter
\pagestyle{mystyle}
\chapter{LALALA LALALA LALALA}
\lipsum[1-8]
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\end{document}
我已经尝试过 Pieter van Oostrum 的答案,但我没有做太多修改。
但是,内容页脚的结果是“PREFACE”。
答案1
- 从页脚中删除
\rightmark
。我认为这没有任何意义。
\fancyfoot[ER]{%
\footnotesize\textbf{INTRODUCTION TO MATLAB}%
}
- 您使用
\Chaptername
左页脚,因此您必须设置它。
\frontmatter
\chapter{PREFACE}
\lipsum[1-5]
\newpage
\renewcommand{\Chaptername}{CONTENTS}
\tableofcontents
\mainmatter
现在,如果您还想在页脚中使用“大写单词”技巧,就像您之前的问题之一一样,这将更改为“目录”而不是“CONTENTS”。如果您不想这样,那么您需要一个\fancyfoot[OL]
不带 的\mycapswords
。最安全的方法是front matter
为此定义一个页面样式。
这是一个完整的例子。笔记:\fancypagestyle
带有可选参数的需要fancyhdr
版本 4。
\documentclass[twoside,11pt]{book}
\usepackage{fancyhdr,xcolor,lipsum}
\usepackage{mfirstuc}
\ExplSyntaxOn
\newcommand\mycapswords[1]{\ecapitalisewords{\text_lowercase:n {#1}}}
\ExplSyntaxOff
\let\Chaptermark\chaptermark
\def\chaptermark#1{\def\Chaptername{#1}\Chaptermark{#1}}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
\colorlet{myfancycolor}{black}
\fancypagestyle{mystyle}{
\renewcommand*\footrulewidth{1pt}
\fancyfoot[OR]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hfil
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
\fancyfoot[OL]{%
\mycapswords{\Chaptername}%
}
\fancyfoot[EL]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
\fancyfoot[ER]{%
\footnotesize\textbf{INTRODUCTION TO MATLAB}%
}
}
\fancypagestyle{frontmatter}[mystyle]{
\fancyfoot[OL]{%
\Chaptername
}
}
\begin{document}
\frontmatter
\pagestyle{frontmatter}
\chapter{PREFACE}
\lipsum[1-5]
\newpage
\renewcommand{\Chaptername}{CONTENTS}
\tableofcontents
\mainmatter
\pagestyle{mystyle}
\chapter{LALALA LALALA LALALA}
\lipsum[1-8]
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\end{document}
答案2
通过对 的代码进行一些更改mystyle
,可以实现使frontmatter
标题与 相同的目标mainmatter
。
该文档的其余部分不需要任何更改。
\documentclass[twoside,11pt]{book}
\usepackage{fancyhdr,xcolor,lipsum}
\colorlet{myfancycolor}{black}
\fancypagestyle{mystyle}{%
\fancyhf{} % added
\renewcommand*{\chaptermark}[1]{ \markboth{##1}{} }% % added <<<<
\renewcommand*\footrulewidth{1pt}
\fancyfoot[RO]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hfil
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
\fancyfoot[LO]{ \leftmark} % <<<<<<<<<<<<<<<<<
\fancyfoot[LE]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to2em{\hss\color{white}{\textsf{\thepage}}\hss}}%
}
\fancyfoot[RE]{%
\footnotesize\textbf{INTRODUCTION TO MATLAB}
}
}
\pagestyle{mystyle}
\begin{document}
\frontmatter
\chapter{PREFACE}
\lipsum[1-5]
\tableofcontents
\mainmatter
\chapter{LALALA LALALA LALALA}
\lipsum[1-8]
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\chapter{LALALA LALALA LALALA}
\end{document}
如果你不想使用双重规则 \renewcommand*\footrulewidth{0pt}
为了统一plain
章节第一页的样式mystyle
,您可以添加
\fancypagestyle{plain}{%
\fancyhf{}
\renewcommand*\headrulewidth{0pt}
\fancyfoot[C]{%
\kern-3ex % all material is shifted up by 3ex
\color{myfancycolor}
\hrule height1pt % your \hrule
\hfill \hbox{\rlap{\vrule height1.3em width2em depth.7em}% you black box
\hbox to 2em{\hss\color{white}{\textsf{\thepage}}\hss}}\hfill%
}
}