我有一份分为两部分的文档(这是我需要多次的模型),每部分都以第 1 页开始。然后我必须写出整个文档的总页数。为此,我使用了 xassoccnt 包。但我的文档有 4 页,而命令 \TotalValue{totalpages} 给出了 7 页(请参阅下面我的代码的第 108 行和第 171 行)!有人能解决这个错误吗?非常感谢!
\documentclass[12pt,a4paper,textsf]{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% READ ME FIRST %
% ************* %
% %
% !!!!! This file has to be runned twice for the command \N to be defined !!!!! %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Préambule
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%BEGIN_FOLD % Packages % Filigrane % Mise en page et en-tête % Macros personnelles
%%%%%%%%%%%%%%%%%%%%%%
% Packages
%%%%%%%%%%%%%%%%%%%%%%
% Pour le français
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
% Pour les en-têtes et la mise en page
\usepackage{fancyhdr}
\usepackage{setspace} %pour \begin{spacing}{...} \end{spacing}
% Pour le nombre total de pages
\usepackage{xassoccnt} % commande \TotalValue{totalpages} (nouveau compteur déclaré à la ligne suivante: `totalpages`)
\DeclareTotalAssociatedCounters{page}{totalpages}
% Pour les énumérations, les citations, les graphiques
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{enumerate}
%%%%%%%%%%%%%%%%%%%%%%
% Mise en page et en-tête
%%%%%%%%%%%%%%%%%%%%%%
% Dimensions du texte
\setlength{\parindent}{0cm}
\addtolength{\textwidth}{3cm}
\addtolength{\textheight}{0.5cm}
\addtolength{\voffset}{-2.5cm}
\addtolength{\hoffset}{-1.2cm}
\setlength{\headheight}{59.51pt}% hauteur de l'en-tête
\setlength{\headsep}{30pt}
\setlength{\footskip}{50pt}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.pt}
%%%%%%%%%%%%%%%%%%%%%%
% Macros personnelles
%%%%%%%%%%%%%%%%%%%%%%
%END_FOLD
%%%%%%%%%%%%%%%%%%%%%%
% Commandes de titre (À ADAPTER)
%%%%%%%%%%%%%%%%%%%%%%
\author{Robin Pereboom}
\newcommand{\session}{mars 20XX}
\newcommand{\DureePartOne}{XX minutes}
\newcommand{\DureePartTwo}{XX minutes}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Début du document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{spacing}{1.5}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Corps du document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PREMIÈRE PARTIE - BEGIN
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%BEGIN_FOLD % Page de garde première partie % Tableau dynamique
\cfoot{\thepage/\pageref{LastPagePart01}}%page X/Y %pied de page centre
%%%%%%%%%%%%%%%%%%%%%%
% Page de garde première partie
%%%%%%%%%%%%%%%%%%%%%%
~
\vspace{1.\baselineskip}
\begin{center}
{\LARGE \textbf{Examen d'admission: session \session}}\\
{\Large École de commerce de Fribourg et Bulle\\
École de culture générale de Fribourg et Bulle}\\
\vspace{2.\baselineskip}
\uppercase{\textbf{\huge Mathématiques}}\\
{\textbf{\LARGE Première partie, sans calculatrice}}\\
\vspace{2.\baselineskip}
\framebox[\textwidth][l]{
\begin{tabular}{ll}
Durée de l'épreuve: &première partie: \DureePartOne\\
&seconde partie: \DureePartTwo\\
&total: 60 minutes\\
\\
Ouvrages et matériel autorisés: &\parbox[t]{9cm}{règle graduée, compas et rapporteur}\\
\\
Barème: & 50 points au total\\
\\
Nombres de pages incluant celle-ci: &première partie: \pageref{LastPagePart01} pages\\
& seconde partie: \pageref{LastPagePart02} pages\\
& total: \TotalValue{totalpages} pages\\
\end{tabular}
}
\end{center}
%***********************************************
\newpage
\part*{\LARGE{Première partie, sans calculatrice}}
\emph{\Large{Durée: \DureePartOne.}}
%END_FOLD
%%%%%%%%%%%%%%%%%%%%%%
% Corps de l'examen - première partie (À ADAPTER)
%%%%%%%%%%%%%%%%%%%%%%
\section{Exercice}
\begin{enumerate}
\item
\item
\end{enumerate}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PREMIÈRE PARTIE - END
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\label{LastPagePart01}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SECONDE PARTIE - BEGIN
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%BEGIN_FOLD % Page de garde seconde partie
\newpage
\cfoot{\thepage/\pageref{LastPagePart02}}%page X/Y %pied de page centre
%the two following lines are needed, instead of only `\setcounter{page}{1}`, for the counter `totalpages` to be at the correct number of pages (and the `page` counter to be reset to the value one at the beginning of the second part)
\setcounter{page}{0}
\stepcounter{page} .
%%%%%%%%%%%%%%%%%%%%%%
% Page de garde seconde partie
%%%%%%%%%%%%%%%%%%%%%%
~
\vspace{1.\baselineskip}
\begin{center}
{\LARGE \textbf{Examen d'admission: session \session}}\\
{\Large École de commerce de Fribourg et Bulle\\
École de culture générale de Fribourg et Bulle}\\
\vspace{2.\baselineskip}
\uppercase{\textbf{\huge Mathématiques}}\\
{\textbf{\LARGE Seconde partie, avec calculatrice}}\\
\vspace{2.\baselineskip}
\framebox[\textwidth][l]{
\begin{tabular}{ll}
Durée de l'épreuve: &première partie: \DureePartOne\\
&seconde partie: \DureePartTwo\\
&total: 60 minutes\\
\\
Ouvrages et matériel autorisés: &\parbox[t]{9cm}{machine à calculer (calculatrice autorisée : Casio fx-85, TI-30 (mais non TI-30X PRO) ou modèle équivalent; en aucun cas une calculatrice graphique, programmable ou permettant de résoudre des équations ne sera autorisée), règle graduée, compas et rapporteur}\\
\\
Barème: & 50 points au total\\
\\
Nombres de pages incluant celle-ci: &première partie: \pageref{LastPagePart01} pages\\
& seconde partie: \pageref{LastPagePart02} pages\\
& total: \TotalValue{totalpages} pages\\
\end{tabular}
}
\end{center}
\newpage
\part*{\LARGE{Seconde partie, avec calculatrice}}
\emph{\Large{Durée: \DureePartTwo.}}
\emph{\textbf {\Large Attention! \large Pour toute cette seconde partie, calculer le plus précisément possible; arrondir ensuite chaque réponse finale au centième.}}
%END_FOLD
%%%%%%%%%%%%%%%%%%%%%%
% Corps de l'examen - seconde partie (À ADAPTER)
%%%%%%%%%%%%%%%%%%%%%%
\section{Exercice}
\begin{enumerate}
\item
\item
\end{enumerate}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SECONDE PARTIE _ END
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\label{LastPagePart02}
\end{spacing}
\end{document}