Fancyhdr 页脚移至一侧

Fancyhdr 页脚移至一侧

我对页脚位置有疑问。我正在使用 fancyhdr,我只希望页脚上的数字位于中心。我正在使用:

  \fancyfoot[C]{\thepage}

但在正常页面中,数字被移到了一边,我不知道为什么。我知道它应该与文本(而不是页面)居中,但它不在它应该在的位置。

此代码重现了该问题:

\documentclass[a4paper,12pt,fleqn,twoside,openright,oldfontcommands]{memoir}

%%%% PACKAGES %%%%
\usepackage{soulutf8}
\usepackage{color}
\usepackage[utf8]{inputenc}                 
\usepackage[T1]{fontenc}
\usepackage[catalan]{babel}
\usepackage[catalan]{varioref}                                          

\let\footruleskip\undefined
\usepackage{fancyhdr}

%%%% CUSTOM SETTINGS %%%%

% ¤¤ MARGINS ¤¤ %
\setlrmarginsandblock{3cm}{2cm}{*}  
\setulmarginsandblock{2.5cm}{2.5cm}{*}  
\checkandfixthelayout                                   

% ¤¤ CHAPTER APPEARANCE ¤¤ %
\usepackage{color,calc,graphicx,soul,fourier}
\definecolor{niceblue}{RGB}{49,79,79}
\makeatletter
\newlength\dlf@normtxtw
\setlength\dlf@normtxtw{\textwidth}
\def\myhelvetfont{\def\sfdefault{mdput}}
\newsavebox{\feline@chapter}
\newcommand\feline@chapter@marker[1][4cm]{%
\sbox\feline@chapter{%
\resizebox{!}{#1}{\fboxsep=1pt%
\colorbox{niceblue}{\color{white}\bfseries\sffamily\thechapter}%
}}%
\rotatebox{90}{%
\resizebox{%
\heightof{\usebox{\feline@chapter}}+\depthof{\usebox{\feline@chapter}}}%
{!}{\scshape\so\@chapapp}}\quad%
\raisebox{\depthof{\usebox{\feline@chapter}}}{\usebox{\feline@chapter}}%
}
\newcommand\feline@chm[1][4cm]{%
\sbox\feline@chapter{\feline@chapter@marker[#1]}%
\makebox[0pt][l]{% aka \rlap
\makebox[1cm][r]{\usebox\feline@chapter}%
}}
\makechapterstyle{daleif1}{
\renewcommand\printchaptertitle[1]{\chaptitlefont\raggedright ##1\par}
\setlength{\midchapskip}{-100pt}
\setlength{\afterchapskip}{2.5cm}
\setlength{\beforechapskip}{-1cm}
\renewcommand\chapnamefont{\normalfont\Large\scshape\raggedleft\so}
\renewcommand\chaptitlefont{\normalfont\huge\bfseries\scshape\color{niceblue}}
\renewcommand\chapternamenum{}
\renewcommand\printchaptername{}
\renewcommand\printchapternum{\null\hfill\feline@chm[2.5cm]\par}
\renewcommand\afterchapternum{\par\vskip\midchapskip}
}
\makeatother
\chapterstyle{daleif1}                                              

\pagestyle{plain}                                                                                           

\begin{document}                                                                                                    

%%%%%%%%%%%%%% HEADERS %%%%%%%%%%%%%% 

\setlength{\headheight}{15pt}

\pagestyle{fancy}

\fancyhf{}
\fancyhead[RE]{\textit{ \nouppercase{Autor}} }
\fancyhead[LO]{\textit{ \nouppercase{\leftmark}} }
\fancyfoot[C]{\thepage}

\fancypagestyle{plain}{ %
  \fancyhf{} % remove everything
  \renewcommand{\headrulewidth}{0pt} % remove lines as well
  \renewcommand{\footrulewidth}{0pt}
  \fancyfoot[C]{\thepage}
}

%%%% Content %%%%
\chapter{Introduction}
\input{text.tex}

\end{document}

肯定有一些与 fancyhdr 不兼容的东西,但我不知道在哪里可以找到它……

谢谢你的时间!

答案1

谢谢朋友们的帮助!我发现了这个问题...

fancyhdr 应该在边距设置之后调用:

%%%% CUSTOM SETTINGS %%%%

% ¤¤ MARGINS ¤¤ %
\setlrmarginsandblock{3cm}{2cm}{*}  
\setulmarginsandblock{2.5cm}{2.5cm}{*}  
\checkandfixthelayout 

\let\footruleskip\undefined
\usepackage{fancyhdr}

现在一切都运行良好。谢谢!

答案2

这里的问题是,fancyhdr似乎使用加载时“有效”的页面几何设置来确定页面中心。

有两种可能性:

  1. (正如 XtracT 在回答他自己的问题时所指出的):fancyhdr改变页面几何形状后加载。

  2. (在我看来更好)因为memoir提供了fancyhdr设置页眉和页脚的方式,所以使用它。

下面是一个例子。顺便说一句,我编辑了 MWE 以删除大量不相关的内容。这实际上是解决问题的必要过程的一部分:可以删除而不会影响它的内容显然是不相关的,人们很快就能找到它。

\documentclass{memoir}                                               
\usepackage{lipsum}
%\usepackage{fancyhdr} Not needed with Memoir

\setlrmarginsandblock{3cm}{2cm}{*}  
\setulmarginsandblock{2.5cm}{2.5cm}{*}  
\checkandfixthelayout

%The problem is with the following code
% \fancypagestyle{plain}{ %
%  \fancyhf{} % remove everything
%  \renewcommand{\headrulewidth}{0pt} % remove lines as well
%  \renewcommand{\footrulewidth}{0pt}
%  \fancyfoot[C]{\thepage}
% }

\makeevenfoot{plain}{}{\thepage}{}
\makeoddfoot{plain}{}{\thepage}{}

\pagestyle{plain}  

\begin{document}                                                                                                    
\lipsum

\end{document}

相关内容