pageref 与 setspace 包冲突?

pageref 与 setspace 包冲突?

我有一份文档,我想在其中以 (页码)/(总页数) 的形式写入每个页码,例如 1/2。我在\label{LastPagePart01}文档末尾和\thepage/\pageref{LastPagePart01}每页底部使用此格式。这适用于每一页,但最后一页除外,因为最后一页只有页码。

我注意到,如果我删除\begin{spacing}{1.5}\end{spacing}命令,那么一切都会正常进行。我还注意到,如果我\newpage在文档末尾的命令之前添加一个命令,\end{spacing}结果也很好。

\pageref是不是说明命令和包有冲突setspace

有人能解决这个问题吗?非常感谢!

\documentclass[12pt,a4paper,textsf]{article}

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

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

            
        \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}
        
    \end{spacing}
\end{document}

答案1

\cfoot命令是本地设置,在这种情况下,最后一页将在之后弹出\end{spacing},因此在组结束时已恢复。如果您在组开始之前设置它,那么它在结束时仍然在范围内

    \cfoot{\thepage/\pageref{LastPagePart01}}%page X/Y %pied de page centre
    \begin{spacing}{1.5}

在此处输入图片描述

它实际上并没有造成问题,但您的标签\label{LastPagePart01}在垂直模式下是自由浮动的,因此如果分页符恰好出现在枚举之后,它可能会与枚举位于同一页,也可能出现在下一页的顶部。因此,更改垂直间距可能会意外地将其推到页面上。所以这实际上不是一个冲突,因为文档标记不安全,并且垂直间距的变化(或对文本的任何更改)可能会导致标签分离。一般来说(可能不是这里),浮动到末尾的数字也会出现在这样的后面,这\label意味着它没有记录最后的页码。

提供总页数的软件包(以及最近版本的乳胶)在任何图形和其他分页问题得到解决后\label,在定义中执行隐藏的内部操作,因此您知道您已经在最后一页。\end{document}

在当前版本中,您可以使用它\PreviousTotalPages来获取上次运行的总页数,而无需明确设置标签。

相关内容