newgeometry 与 fancyhdr 之间的交互

newgeometry 与 fancyhdr 之间的交互

为了使论文的题词居中,我必须对该页使用 newgeometry。下一页的页码现在丢失了,并且 fancyhdr 给出了以下警告:

软件包 Fancyhdr 警告:\fancyfoot 的 `E' 选项如果没有 twoside 选项,在输入行 ** 上是无用的。

我创建了一个 MWE,它用尽可能少的行显示问题。如果您注释掉包含 restoregeometry 命令的 newgeometry 块,则错误消息会消失并显示页码。在 restoregeometry 命令之后再次调用 thispagestyle 和/或 pagestyle 不会有帮助。


平均能量损失

\documentclass[twoside]{article}
\usepackage[utf8]{inputenc}

\usepackage{%
    geometry,%
    fancyhdr,%
    parskip,%
    xparse,%
}


\geometry{%
    paper = a4paper,%
    top = 3cm,%
    bottom = 3.5cm,%
    inner = 3.5cm,%
    outer = 2.5cm,%
    nomarginpar,%
    showframe = true%
}


\fancypagestyle{noheader}{%
    \fancyhf{}                  % Clean fields
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0.4pt}
    \fancyfoot[LE, RO]{\thepage}%
}


\NewDocumentEnvironment{dedication}{}{%
    \newpage%
    \newgeometry{%
        top = 0cm,%
        bottom = 3.5cm,%
        inner = 3.5cm,%
        outer = 2.5cm,%
        nomarginpar,%
    }
    \vspace*{\fill}
    \itshape%
    \centering%
}{%
    \vspace*{\fill}%
    \restoregeometry%
    \newpage%
}

\begin{document}
\thispagestyle{noheader}%
\pagestyle{noheader}%

This is only the first page. On the next page, the dedication will be displayed.

\begin{dedication}
I'm a touching dedication
\end{dedication}

I'm the third page. Note that I do not have a page number, even though the first and the second page have one.

\end{document}

编辑

这些是应用 egregs answer 后的日志输出。

] [2]) (./dedication.tex [3

] [4]
*geometry* verbose mode - [ newgeometry ] result:
* driver: xetex
* paper: a4paper
* layout: <same size as paper>
* layoutoffset:(h,v)=(0.0pt,0.0pt)
* modes: 
* h-part:(L,W,R)=(99.58464pt, 426.79135pt, 71.13188pt)
* v-part:(T,H,B)=(0.0pt, 745.4622pt, 99.58464pt)
* \paperwidth=597.50787pt
* \paperheight=845.04684pt
* \textwidth=426.79135pt
* \textheight=745.4622pt
* \oddsidemargin=27.31465pt
* \evensidemargin=27.31465pt
* \topmargin=-109.26999pt
* \headheight=12.0pt
* \headsep=25.0pt
* \topskip=10.0pt
* \footskip=30.0pt
* \marginparwidth=0.0pt
* \marginparsep=0.0pt
* \columnsep=10.0pt
* \skip\footins=9.0pt plus 4.0pt minus 2.0pt
* \hoffset=0.0pt
* \voffset=0.0pt
* \mag=1000
* \@twocolumnfalse
* \@twosidefalse
* \@mparswitchfalse
* \@reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)



Package Fancyhdr Warning: \fancyfoot's `E' option without twoside option is useless on input line 5.

答案1

\restoregeometry您应该在环境结束后申请。

%我还通过删除不必要的部分并在必要时添加它们来修复代码。也比这个上下文\clearpage更好。如果您愿意,可以删除设置。\newpage\thispagestyle{empty}

\documentclass[twoside]{article}
\usepackage[utf8]{inputenc}

\usepackage{
    geometry,
    fancyhdr,
    parskip,
    xparse,
}


\geometry{
    paper = a4paper,
    top = 3cm,
    bottom = 3.5cm,
    inner = 3.5cm,
    outer = 2.5cm,
    nomarginpar,
%    showframe = true
}


\fancypagestyle{noheader}{%
    \fancyhf{}% Clean fields
    \renewcommand{\headrulewidth}{0pt}%
    \renewcommand{\footrulewidth}{0.4pt}%
    \fancyfoot[LE, RO]{\thepage}%
}


\NewDocumentEnvironment{dedication}{}{%
    \clearpage
    \newgeometry{
        top = 0cm,
        bottom = 3.5cm,
        inner = 3.5cm,
        outer = 2.5cm,
        nomarginpar,
    }
    \thispagestyle{empty}
    \vspace*{\fill}
    \itshape
    \centering
}{%
    \par\vspace*{\fill}
    \clearpage
    \aftergroup\restoregeometry
}

\begin{document}
\pagestyle{noheader}

This is only the first page. On the next page, the dedication will be displayed.

\begin{dedication}
I'm a touching dedication
\end{dedication}

I'm the third page. Note that I do not have a page number, even though the 
first and the second page have one.

\end{document}

另一方面,我认为没有什么真正的理由\newgeometry,只是将奉献精神稍微往上移一点。

在此处输入图片描述

相关内容