1

So I'm trying to rewrite my own template to the memoir document class and I've run into an issue. I have this page numbering on top which says "Page 6 of 8" which works perfectly. But since I've made this the memoir class and want to use front matter, main matter and back matter, I end up in the front matter with "Page v of 8", which is the fifth page of the front matter and the 8th page of the main matter, which is not what I want.

Can you guys help me figure out on how to get "Page v of v" on the front matter and "Page 6 of 8" on main matter?

This is part of my source code.

Document.tex

\documentclass[12pt,openany]{memoir}

\include{src/preamble}

\providecommand{\versionnumber}{1.0}
\providecommand{\projectname}{Project X}  
\providecommand{\documentname}{Document Y}

\begin{document}
    \include{src/TitlePage}
    \begin{frontmatter}
        \include{chapters/VersionControl}
        \tableofcontents
        \include{src/Abbreviations}
        \include{chapters/Introduction}
    \end{frontmatter}

    \begin{mainmatter}
        \include{chapters/ExampleChapter}
    \end{mainmatter}
    %\nocite{*} %Add this line whenever any entries in the bibliography are not cited, but need to be added.
    \bibliography{src/bib}
    %\begin{appendices} %Uncomment for appendices
    %\end{appendices}

\end{document}

preamble.tex

% This template has been made AS IS by Foitn©.
% It has been made as a school project and can be used by anyone for free.
% Feel free to take from this template or to edit this to your needs.
% In no event are the creaters of this template responsible for any data loss or any warranty or support.
% Enjoy!

\usepackage[export]{adjustbox}          % Place an image on the right or left side of the page
\usepackage[utf8]{inputenc}                 % Character usage
\usepackage[T1]{fontenc}                    % Font encoding
\usepackage[sfdefault]{universalis}     % Font used The UniversalisADFStd-Regular-lf-ts1--base source file could not be found
\usepackage[margin=1in]{geometry}               % Page margins
\usepackage{fancyhdr}                   % Creating own headers and footers
\usepackage{titlesec}                       % Used to get chapter and the name on the same line
\usepackage{etoolbox}                   % Needed to enabled editing of section titles
\usepackage[]{hyphenat}                 % Used to hyphen all text at in a neat way
\usepackage{graphicx}                   % Include graphics, like images
\usepackage{wrapfig}                    % To get an image and text next to eachother
\usepackage[hidelinks]{hyperref}            % To make links and make them clickable
\usepackage{nameref}
\usepackage{tabularx}                   % To create a diffent table which has a predefined width
\usepackage{lastpage}                   % Get the total amount of pages in the document
\usepackage{acro}                       % Create a list of acronyms
\usepackage[tocbib]{apacite}                % Use apa for the bibliography
\usepackage[english]{babel}             % 
\usepackage[square,numbers]{natbib} % Create bibliography
\usepackage[noabbrev]{cleveref}
\usepackage{longtable}
\usepackage{subcaption}
\usepackage{tabu}
\usepackage{booktabs}
\usepackage{color}
\usepackage{pdflscape}
\usepackage{multirow}
\usepackage{adjustbox}
\usepackage{array}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{lipsum}

\bibliographystyle{apacite}

%------------------------------------------------------------------------------
% Custom commands
%------------------------------------------------------------------------------
\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}
\makeatletter
\patchcmd{\@smemmain}{\cleardoublepage}{\clearpage}{}{}
\patchcmd{\@smemmain}{\cleardoublepage}{\clearpage}{}{}
\makeatother
%-------------------------------------------------------------------------------
% Header and footer
%-------------------------------------------------------------------------------
\setlength{\headwidth}{0.964\textwidth}
\fancypagestyle{plain}{
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \fancyhead[L]{
        \vspace{-3cm}
        \documentname ,  \projectname \\
        \HRule{1pt}
    }
    \fancyhead[R]{
        \vspace{-3cm}
        Page \thepage \space of \thelastpage\\
        \HRule{1pt}
    }
}
\pagestyle{plain}
%-------------------------------------------------------------------------------
% Page layout 
%-------------------------------------------------------------------------------

\geometry{
    paper=a4paper, % Change to letterpaper for US letter
    top=4.5cm, % Top margin
    bottom=4cm, % Bottom margin
    headsep=1.5cm,
}
\newtoggle{aftersection}
\preto{\section}{\filbreak\global\toggletrue{aftersection}}
\preto{\subsection}{\iftoggle{aftersection}{\global\togglefalse{aftersection}}{\filbreak}}
\newcommand{\clearpageafterfirst}{
    \gdef\clearpageafterfirst{\clearpage}
}
%-------------------------------------------------------------------------------
% Font 
%-------------------------------------------------------------------------------
\definecolor{chaptercolor}{RGB}{0,32,96}
\definecolor{sectioncolor}{RGB}{0,32,96}
\definecolor{subsectioncolor}{RGB}{0,32,96}
\definecolor{subsubsectioncolor}{RGB}{0,0,0}

\hyphenpenalty 10000
\exhyphenpenalty 10000
\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@}
\titleformat*{\section}{\normalfont\fontfamily{phv}\fontsize{16}{19}}
\titleformat*{\subsection}{\normalfont\fontfamily{phv}\fontsize{14}{17}}
\titleformat*{\subsubsection}{\normalfont\fontfamily{phv}\fontsize{14}{17}\selectfont}

\renewcommand\printtoctitle[1]{{\normalfont\LARGE\bfseries\color{chaptercolor}#1}{\LARGE}}
\titleformat{\chapter}[hang]{\normalfont\LARGE\bfseries\color{chaptercolor}}{\chaptertitlename\ \thechapter:}{20pt}{\LARGE}
\titlespacing*{\chapter}{0pt}{-50pt}{20pt}
\titleformat{\section}[hang]{\normalfont\large\bfseries\color{sectioncolor}}{}{0pt}{\Large}
\titleformat{\subsection}[hang]{\normalfont\large\bfseries\color{subsectioncolor}}{}{0pt}{\bfseries}
\titleformat{\subsubsection}[hang]{\normalfont\bfseries\color{subsubsectioncolor}}{}{0pt}{}
3
  • 1
    Oh how i love those examples whre you have to puzzle together the pieces and guess some other pieces just to find out my guessing was wrong. Why don't you post a minimal working example right from the beginning?
    – Johannes_B
    Oct 3, 2017 at 9:07
  • 1
    What you have to do is to add another label at the end of the frontmatter. Apart from that, i wouldn't use memoir with that code. It is clearly set up to work with the standard classes and some of the redefinition are just .... bad.
    – Johannes_B
    Oct 3, 2017 at 9:09
  • See the memoir manual this is directly build in, section 18.4, no need for extra packages.
    – daleif
    Oct 3, 2017 at 10:33

1 Answer 1

1

In your preamble, you have \usepackage{lastpage}. The package author recommends to use package pageslts if different pagenumbering schemes (roman, arabic etc.) are used in a document. I have made use of this package in the following MWE. Please note that \pagenumbering{roman} and \pagenumbering{arabic} are not really necessary here as these directives are automatically triggered by \frontmatter and \mainmatter in the memoir class.

\documentclass[12pt,openany]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{etoolbox}

\usepackage[pagecontinue=false]{pageslts}

\providecommand{\versionnumber}{1.0}
\providecommand{\projectname}{Project X}
\providecommand{\documentname}{Document Y}

\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}
\makeatletter
\patchcmd{\@smemmain}{\cleardoublepage}{\clearpage}{}{}
\patchcmd{\@smemmain}{\cleardoublepage}{\clearpage}{}{}
\makeatother


\newcommand{\lastpageofpart}{\lastpageref{pagesLTS.roman}}

\setlength{\headwidth}{0.964\textwidth}
\fancypagestyle{plain}{
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \fancyhead[L]{
        \vspace{-3cm}
        \documentname ,  \projectname \\
        \HRule{1pt}
    }
    \fancyhead[R]{
        \vspace{-3cm}
        Page \thepage \space of \lastpageofpart\\
        \HRule{1pt}
    }
}


\begin{document}
\frontmatter
\pagestyle{plain}
\pagenumbering{roman}
        \tableofcontents
\chapter{Foreword}
\lipsum

\mainmatter
\renewcommand{\lastpageofpart}{\lastpageref{pagesLTS.arabic}}
\pagenumbering{arabic}
\chapter{Stuff}
\lipsum

\chapter{More stuff}
\lipsum

\end{document}

You must log in to answer this question.

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