在书籍类中,如何创建“页首页眉”,与我什么都不做时得到的页眉略有不同。我为此所做的努力被注释掉了

在书籍类中,如何创建“页首页眉”,与我什么都不做时得到的页眉略有不同。我为此所做的努力被注释掉了
\documentclass[english,11pt,twoside,openright]{book}

\usepackage[fleqn]{amsmath} %
\usepackage{amsthm,amssymb} %
\usepackage{fancyhdr,fancyref} %
\usepackage{xcolor} %
\usepackage{colortbl} %
\usepackage[skins,theorems,most]{tcolorbox} %
\usepackage{xcolor} %
\usepackage[paperwidth=170mm,paperheight=240mm,bindingoffset=12.5mm,left=12.5mm,right=12.5mm,top=18mm,bottom=8mm,showframe,showcrop]{geometry}
\usepackage[a4,frame,cam,center]{crop} %
\usepackage{libertine} %
\usepackage{hyperref}

% \renewcommand{\chaptermark}[1]{\markboth{\fontsize{12.0}{14}\selectfont{\chaptername\hspace{2.8pt}\thechapter\hspace{8pt}-\hspace{8pt}#1}}{}} % 42

% \renewcommand{\sectionmark}[1]{\markright{\fontsize{12.0}{14}\selectfont{Section\hspace{3.6pt}\thesection\hspace{8pt}-\hspace{8pt}#1}}{}} % 32

% \fancypagestyle{mainstyle}{
% \fancyhead{} %
% \fancyfoot{} %
% \fancyhead[LE]{\leftmark} %
% \fancyhead[LO]{\rightmark} %
% \fancyfoot[CE,CO]{\fontsize{11.15}{14}\selectfont{-\hspace{2pt}{\thepage}\hspace{2pt}-}} }

\begin{document}

\chapter{The undeveloped world}

Large areas of land where population density is low.

\section[the Amazon river basin]{The Amazon river basin}

\clearpage

\section[the African river Congo]{The African river Congo}

\clearpage

\chapter{The developed world}

The population density is high.

\section[Europe - from UK in north to Spain in south]{Europe - from UK in north to Spain in south}

\clearpage

\section[North America and Canada]{North America and Canada}

\clearpage

\section[the Philippenes]{Japan and the Philippenes}

\end{document}

答案1

无需定义特定的页面样式,只需发出\pagestyle{fancy}

此外,格式说明应在页眉或页脚的规范中,而不是在标记的说明中。

我将连字符改为短破折号:在我看来,连字符不是正确的选择(太粗且太短)。

不要忘记遵循fancyhdr有关的建议\headheight

\documentclass[11pt,twoside,openright]{book}

\usepackage[fleqn]{amsmath}
\usepackage{amsthm,amssymb}
\usepackage{fancyhdr,fancyref}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage[skins,theorems,most]{tcolorbox}
\usepackage{xcolor}
\usepackage[
  paperwidth=170mm,
  paperheight=240mm,
  bindingoffset=12.5mm,
  left=12.5mm,
  right=12.5mm,
  top=18mm,
  bottom=8mm,
  headheight=14pt,% as requested by fancyhdr
%  showframe,
%  showcrop
]{geometry}
\usepackage[a4,frame,cam,center]{crop}
\usepackage{libertine}
\usepackage{hyperref}

\renewcommand{\chaptermark}[1]{%
  \markboth{\chaptername\hspace{2.8pt}\thechapter\hspace{8pt}--\hspace{8pt}#1}{}%
}
\renewcommand{\sectionmark}[1]{%
  \markright{Section\hspace{3.6pt}\thesection\hspace{8pt}--\hspace{8pt}#1}%
}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE]{\fontsize{12}{14}\selectfont\leftmark}
\fancyhead[LO]{\fontsize{12.0}{14}\selectfont\rightmark}
\fancyfoot[C]{\fontsize{11.15}{14}\selectfont{--\hspace{2pt}{\thepage}\hspace{2pt}--}}

\begin{document}

\chapter{The undeveloped world}

Large areas of land where population density is low.

\section{The Amazon river basin}

\clearpage

\section{The African river Congo}

\clearpage

\chapter{The developed world}

The population density is high.

\section{Europe - from UK in north to Spain in south}

\clearpage

\section{North America and Canada}

\clearpage

\section{Japan and the Philippines}

\end{document}

在此处输入图片描述

在此处输入图片描述

答案2

您可以通过以下方式定义新标题fancyhdr's \fancypagestyle(正如你所做的那样),但这不会影响它们的使用,除非你指定它,或者更改默认值。为此,请在定义新页面样式后立即指定要使用的新页面样式:

%...
\usepackage{fancyhdr}
%...
\fancypagestyle{mainstyle}{%
  % <your mainstyle page style definitions
}
%...
\pagestyle{mainstyle}% mainstyle page style in effect from here
%...

当然,请注意,\chapter只有第一页才有自己的页面样式,通常通过 发出\thispagestyle{plain}。如果您想覆盖此行为,可以定义新样式来替换plain,或重新定义plain页面样式。


根据您的具体示例,输入应该是这样的(我从您的示例中删除了一些不必要的包):

\documentclass[twoside,openright]{book}

\usepackage{fancyhdr}
\usepackage[paperwidth=170mm,paperheight=240mm,bindingoffset=12.5mm,left=12.5mm,right=12.5mm,top=18mm,bottom=8mm,showframe,showcrop]{geometry}
\usepackage[a4,frame,cam,center]{crop}
\usepackage{libertine}

\renewcommand{\chaptermark}[1]{%
  \markboth
    {\fontsize{12}{14}\selectfont\chaptername\hspace{2.8pt}\thechapter\hspace{8pt}-\hspace{8pt}#1}%
    {}%
} % 42

\renewcommand{\sectionmark}[1]{%
  \markright
  {\fontsize{12}{14}\selectfont Section\hspace{3.6pt}\thesection\hspace{8pt}-\hspace{8pt}#1}%
  {}%
} % 32

% Define mainstyle page style
\fancypagestyle{mainstyle}{%
  \fancyhf{}% Clear header/footer
  \fancyhead[LE]{\leftmark}%
  \fancyhead[LO]{\rightmark}%
  \fancyfoot[CE,CO]{\fontsize{11.15}{14}\selectfont -\hspace{2pt}{\thepage}\hspace{2pt}-}%
}
\setlength{\headheight}{14pt}% Based on the size of the header content

% Set mainstyle as the current page style
\pagestyle{mainstyle}

\begin{document}

\chapter{The undeveloped world}

Large areas of land where population density is low.

\section[the Amazon river basin]{The Amazon river basin}

\clearpage

\section[the African river Congo]{The African river Congo}

\clearpage

\chapter{The developed world}

The population density is high.

\section[Europe - from UK in north to Spain in south]{Europe - from UK in north to Spain in south}

\clearpage

\section[North America and Canada]{North America and Canada}

\clearpage

\section[the Philippenes]{Japan and the Philippenes}

\end{document}

相关内容