Fancyhdr 不显示页码

问题描述

我正在为 fancyhdr 包苦苦挣扎。具体来说,有以下几点:

\fancypagestyle{mystyle}{
\fancyhead{}
\fancyfoot[C]{\thepage}
\setlength{\headheight}{180pt}
\chead{\includegraphics[width=8cm]{x.png}}
}

使用 \thispagestyle{mystyle} 时,页眉显示正确,但页码根本不显示。有人可以帮我吗?

解决方法

在标准的 Latex 类中,没有足够的空间容纳 180pt 高度的页眉而不会将页脚推离页面。如果降低文本区域的高度,可以看到实际打印了页码:

\documentclass{article}
\usepackage{graphicx}
\usepackage{fancyhdr}
\fancypagestyle{mystyle}{
\fancyhead{}
\fancyfoot[C]{\thepage}
\setlength{\headheight}{180pt}
\chead{\includegraphics[width=8cm]{example-image-duck}}
}

\usepackage[includeheadfoot,height=15cm]{geometry}

\begin{document}

\thispagestyle{mystyle}

test


\end{document}