页码 当前页码 最后一页

页码 当前页码 最后一页

因此,我尝试将自己的模板重写为回忆录文档类,但遇到了一个问题。我在顶部有页码,上面写着“第 6 页,共 8 页”,效果很好。但由于我已将其设为回忆录类,并希望使用前言、正文和后记,因此我最终在前言中出现了“第 v 页,共 8 页”,即前言的第五页和正文的第八页,这不是我想要的。

你们能帮我弄清楚如何在前言中获得“第 v 页,共 v 页”以及在正文中获得“第 6 页,共 8 页”吗?

这是我的源代码的一部分。

文档.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}

序言.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}{}

答案1

在您的序言中,您有。如果文档中使用了不同的页码方案(罗马、阿拉伯等),则\usepackage{lastpage}包作者建议使用包。我在以下 MWE 中使用了这个包。请注意,和在这里并不是真正必要的,因为这些指令是由memoir 类中的和自动触发的。pageslts\pagenumbering{roman}\pagenumbering{arabic}\frontmatter\mainmatter

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

相关内容