如何使前言章节第一页的页眉与主内容章节第一页的页眉不同

如何使前言章节第一页的页眉与主内容章节第一页的页眉不同

我正在写论文,并将文档分为\frontmatter\mainmatter\backmatter。对于页眉,我使用 fancyhd 并重新定义,\pagestyle{plain}因此第一章页面为空白(页脚中没有页码),但我想重新定义前言页面的页眉,以便章节的第一页和下一页在页眉上没有行(因此没有 fancyhd)和罗马数字页码,而主要章节的第一页保持空白,其他页面有章节名称、页码和下面的行。

前言中的所有页面应如下所示:

在此处输入图片描述

并且主要内容的页面(除了保持空白的章节第一页之外)应继续如下所示:

在此处输入图片描述

我尝试\if@mainmatter按照另一篇文章中的建议在定义 pagestyle{plain} 时添加,但无法编译。

我该怎么做?提前致谢

代码(可编译)如下:

\documentclass[a4paper, 12pt, oneside]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{indentfirst}
\usepackage{fancyhdr} %fancy header and footer
\usepackage[colorlinks=true, linkcolor=black]{hyperref}
\usepackage{afterpage} % page break without beeing counted

%%%%%%%%%%%%%%% Layout
\chapterstyle{article} %chapter title in bold, lefrangged, no flourish

%Header and foot
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyfoot{}
\fancyhf{}
\lhead[\thepage]{\textit{\leftmark}} 
\rhead[\nouppercase{\rightmark}]{\thepage}
\fancypagestyle{plain}{%header chapter first page
%\if@mainmatter%
\renewcommand{\headrulewidth}{0pt} %no header
\fancyfoot{} %no foot
\fancyhf{}
%\lhead[\thepage]{\textit{\leftmark}} 
%\rhead[\nouppercase{\rightmark}]{\thepage} 
    }

%%%%%%%%%%%%%%%% newcommand
\newcommand{\knc}[1]{\textit{#1}}
 \newcommand{\kpage}[1]{%
    \newpage
      \addtocounter{page}{-1}
      \thispagestyle{empty}
      \vspace{\fill}
      \begin{flushright}
         \vspace{85pt}
         \vspace*{\fill}
         \HUGE{\textbf{\textit{#1}}}
         \vspace*{2cm}
      \end{flushright}
   }


%%%%%%%%%%%%%%%% begin doc
\begin{document}
   \frontmatter

    \chapter*{}%%% abstract
Fisrt chapter page (frontmatter) - should have a roman page number on the right corner of the header, with no line beneath
\clearpage
Secong page (frontmatter) - I'm trying to get rid of the line from fancyhd, but not the page number 
\mainmatter
  

   \kpage{Introduction}
   \chapter{Introduction}
First chapter page (mainmatter) - should remain as it is
\clearpage
Second page - likewise

\backmatter
\end{document}

答案1

该类memoir提供了自己的方法来定义标题。请参阅手册中的第 7 章“分页和标题”。下面是您的 MWE,只是我memoir在序言末尾添加了标题的代码。

%chapmempageprob.tex  SE 612428

\documentclass[a4paper, 12pt, oneside]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{indentfirst}
\usepackage{fancyhdr} %fancy header and footer
\usepackage[colorlinks=true, linkcolor=black]{hyperref}
\usepackage{afterpage} % page break without beeing counted

\usepackage{comment}

%%%%%%%%%%%%%%% Layout
\chapterstyle{article} %chapter title in bold, lefrangged, no flourish

%Header and foot
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyfoot{}
\fancyhf{}
\lhead[\thepage]{\textit{\leftmark}} 
\rhead[\nouppercase{\rightmark}]{\thepage}
\makeatletter
\fancypagestyle{plain}{%header chapter first page
%%\if@mainmatter
\renewcommand{\headrulewidth}{0pt} %no header
\fancyfoot{} %no foot
\fancyhf{}
%\lhead[\thepage]{\textit{\leftmark}} 
%\rhead[\nouppercase{\rightmark}]{\thepage} 
    }
\makeatother

%%%%%%%%%%%%%%%% newcommand
\newcommand{\knc}[1]{\textit{#1}}
 \newcommand{\kpage}[1]{%
    \newpage
      \addtocounter{page}{-1}
      \thispagestyle{empty}
      \vspace{\fill}
      \begin{flushright}
         \vspace{85pt}
         \vspace*{\fill}
         \HUGE{\textbf{\textit{#1}}}
         \vspace*{2cm}
      \end{flushright}
   }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% initial memoir's header code
\makepagestyle{frontm} % for the frontmatter (and elsewhere if necessary
\makeevenhead{frontm}{\thepage}{}{} % even page number top left
\makeoddhead{frontm}{}{}{\thepage} % odd page number top right

\aliaspagestyle{chapter}{frontm} % use frontm as the page style for chapters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%% begin doc
\begin{document}
   \frontmatter

\pagestyle{frontm}

    \chapter*{}%%% abstract
Fisrt chapter page (frontmatter) - should have a roman page number on the right corner of the header, with no line beneath
\clearpage
Secong page (frontmatter) - I'm trying to get rid of the line from fancyhd, but not the page number 
\mainmatter
  

   \kpage{Introduction}
   \chapter{Introduction}
First chapter page (mainmatter) - should remain as it is
\clearpage
Second page - likewise

\backmatter
\end{document}

请注意,memoir章节的第一页设置的chapter页面样式最初设置为plain页面样式。

我希望我正确理解了你的问题。

编辑

根据您的评论,我发布了一个修订后的答案,希望它能满足您的要求。修订内容涉及页面样式以及memoir它们在文档中的使用方式。我还添加了一些文本以提供更多页面。\frontmatter\mainmatter

% chapmempageprob.tex  SE 612428

\documentclass[a4paper, 12pt, oneside]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{indentfirst}
\usepackage{fancyhdr} %fancy header and footer
\usepackage[colorlinks=true, linkcolor=black]{hyperref}
\usepackage{afterpage} % page break without beeing counted

%%%%%%%%%%%%%%% Layout
\chapterstyle{article} %chapter title in bold, lefrangged, no flourish

%Header and foot
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyfoot{}
\fancyhf{}
\lhead[\thepage]{\textit{\leftmark}} 
\rhead[\nouppercase{\rightmark}]{\thepage}
\makeatletter
\fancypagestyle{plain}{%header chapter first page
%%\if@mainmatter
\renewcommand{\headrulewidth}{0pt} %no header
\fancyfoot{} %no foot
\fancyhf{}
%\lhead[\thepage]{\textit{\leftmark}} 
%\rhead[\nouppercase{\rightmark}]{\thepage} 
    }
\makeatother

%%%%%%%%%%%%%%%% newcommand
\newcommand{\knc}[1]{\textit{#1}}
 \newcommand{\kpage}[1]{%
    \newpage
      \addtocounter{page}{-1}
      \thispagestyle{empty}
      \vspace{\fill}
      \begin{flushright}
         \vspace{85pt}
         \vspace*{\fill}
         \HUGE{\textbf{\textit{#1}}}
         \vspace*{2cm}
      \end{flushright}
   }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%memoir's header code
\makepagestyle{frontm} % for the frontmatter (and elsewhere if necessary
\makeevenhead{frontm}{\thepage}{}{} % even page number top left
\makeoddhead{frontm}{}{}{\thepage} % odd page number top right

\makepagestyle{mainm} % for the mainmatter (and elsewhere if necessary}
\makeoddhead{mainm}{\itshape\leftmark}{}{\thepage}
\makeheadrule{mainm}{\textwidth}{0.4pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{lipsum}

%%%%%%%%%%%%%%%% begin doc
\begin{document}
   \frontmatter

\pagestyle{frontm} % use frontm page style for all non-chapter pages
\aliaspagestyle{chapter}{frontm} % use frontm as the page style for chapters


    \chapter*{}%%% abstract
Fisrt chapter page (frontmatter) - should have a roman page number on the right corner of the header, with no line beneath
\clearpage
Secong page (frontmatter) - I'm trying to get rid of the line from fancyhd, but not the page number.

\lipsum[1-5] 
\mainmatter
  
\pagestyle{mainm} % use mainm pagestyle for all pages, except
\aliaspagestyle{chapter}{empty} % use empty as the page style for chapters

   \kpage{Introduction}
   \chapter{Introduction}
First chapter page (mainmatter) - should remain as it is
\clearpage
Second page - likewise

\lipsum[1-5]

\backmatter
\end{document}

相关内容