1

I'm writing my theses and have divided the document in \frontmatter, \mainmatter and \backmatter. For the headers I'm using fancyhd and have redefined \pagestyle{plain} so the first chapter page is blank (with no page number in the footer) but I would like to redefine the headers of the frontmatter pages so the first page of a chapter and the next pages have no line on header (so no fancyhd) and a roman numeral page number while the first pages of the mainmatter chapters stays empty and the other pages has the chapter name, pagenumber and line below.

All pages in the frontmatter should look like this:

enter image description here

And the pages of the mainmatter, except the chapter first page which stays empty should continue looking like this:

enter image description here

I've tried adding \if@mainmatter when defining the pagestyle{plain} as suggested in another post but could not compile.

How could I do it? Thanks in advance

Code (compilable) below:

\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

1 Answer 1

3

The memoir class provides its own methods for defining headers. See Chapter 7 "Pagination and headers" in the manual. Below is your MWE except that I have added memoir code for your headers at the end of your preamble.

%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}

Note that in memoir a chapter's first page is set with the chapter page style which is initially set to the plain pagestyle.

I hope that I have understood your question correctly.

EDIT

Following your comment I am posting a revised answer which, I hope, does what you are after. The revisions pertain to the memoir page styles and how they are used in the document after \frontmatter and \mainmatter. I also added some text to give some more pages.

% 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}
3
  • Thanks for the answer, I used fancyhd so I have the line below on the mainmatter, I don't know if the is another way to do it. I've added your code and compiled. The first chapter page in the front matter is the way I hopped, however now I have an arabic number in the mainmatter chapter front page as well. As for the other pages on the frontmatter, they still have the line below. I've edited the question adding pictures to be clearer on what I need.
    – Bags
    Commented Aug 29, 2021 at 23:34
  • 2
    @Bags Following your comment and added pictures to your question, I have added a revised MWE to my answer which, I hope, satisfies your need. Commented Aug 30, 2021 at 17:29
  • That's exactly what I wanted! Thank you very much!
    – Bags
    Commented Sep 2, 2021 at 14:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .