浮动页面的花式页眉页脚

浮动页面的花式页眉页脚

我正在尝试使用 保留浮动页面上的页码fancyhdr。这是我当前的设置:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
% with this we ensure that the chapter and section
% headings are in lowercase.
%\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\iffloatpage{}{\thesection.\ #1}}}
\fancyhf{} % delete current setting for header and footer
\fancyhead[LE,RO]{\iffloatpage{}{\textbf{Page \thepage\ of \pageref{LastPage}}}}
\fancyhead[LO]{\iffloatpage{}{\textbf\rightmark}}
\fancyhead[RE]{\iffloatpage{}{\textbf\leftmark}}
\renewcommand{\headrulewidth}{\iffloatpage{0pt}{0.5pt}}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\headsep}{10pt}
\iffloatpage{\cfoot{\textbf{Page \thepage\ of \pageref{LastPage}}}}{}
\addtolength{\headheight}{\baselineskip} % make space for the rule
\fancypagestyle{plain}{%
\fancyhead{} % get rid of headers on plain pages
\renewcommand{\headrulewidth}{0pt} % and the line
}

\begin{document}

\begin{figure}
\includegraphics{demo}
\end{figure}

\end{document}

不幸的是,我以为可以实现我想要的功能的那一行 ( \iffloatpage{\cfoot{\textbf{Page \thepage\ of \pageref{LastPage}}}}{}) 什么也没做。我做错了什么?

答案1

反过来说,你需要它:

\fancyfoot[C]{\iffloatpage{\textbf{Page \thepage\ of \pageref{LastPage}}}{}}

代码:

\documentclass[twoside]{article}
\usepackage[demo]{graphicx}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
% with this we ensure that the chapter and section
% headings are in lowercase.
%\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\iffloatpage{}{\thesection.\ #1}}}
\fancyhf{} % delete current setting for header and footer
\fancyhead[LE,RO]{\iffloatpage{}{\textbf{Page \thepage\ of \pageref{LastPage}}}}
\fancyhead[LO]{\iffloatpage{}{\textbf\rightmark}}
\fancyhead[RE]{\iffloatpage{}{\textbf\leftmark}}
\fancyfoot[C]{\iffloatpage{\textbf{Page \thepage\ of \pageref{LastPage}}}{}}
\renewcommand{\headrulewidth}{\iffloatpage{0pt}{0.5pt}}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\headsep}{10pt}
\addtolength{\headheight}{\baselineskip} % make space for the rule
\fancypagestyle{plain}{%
\fancyhead{} % get rid of headers on plain pages
\renewcommand{\headrulewidth}{0pt} % and the line
}

\begin{document}

\begin{figure}
\includegraphics{demo}
\end{figure}

\end{document}

在此处输入图片描述

我添加了twoside类选项;否则,EO没有用。

相关内容