首页 > 解决方案 > 我的页脚在 R-Markdown 的第一页(但不是页眉!)之后消失了

问题描述

我通过在 R-Markdown 生成的 PDF 中使用 fancyhdr 包设置了页脚和页眉。但是,在某些时候,我注意到我的页脚在第一页之后消失了,而我的页眉按预期出现在每一页中。我不知道为什么会这样,我尝试了很多东西,但到目前为止似乎没有任何效果。

header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyfoot{}
- \fancyhead{}
- \renewcommand{\headrulewidth}{0pt}

... (some chunks of code go here)

\fancyhead[L]{\includegraphics[width=4cm]{/Users/username/Documents/SP_logo_login.png}}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage} \\ \today , \currenttime}
\fancyfoot[L]{Identification Report \\ User generating the report: {`r paste(user_code)`}}

\vspace*{1\baselineskip}

# IDENTIFICATION REPORT

(some more LaTex and code chunks follow, including bar plots and KableExtra tables)

...

不管我是把fancyfoot放在一些代码之后还是放在header-includes下面。结果是一样的。页脚在第一页上正确生成,但仅此而已,而页眉出现在每一页的开头。

知道会发生什么吗?

标签: latexmarkdownr-markdownpdflatex

解决方案


您的标题远高于默认标题\headheight,因此会将内容和脚注推离页面。其中有一个明确的警告.log,告诉您标题需要多高。确切的值将取决于图像的纵横比,对于我使用的示例图像,它约为 75pt

---
output:
  pdf_document:
    keep_tex: true

header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyfoot{}
- \fancyhead{}
- \renewcommand{\headrulewidth}{0pt}    
- \geometry{head=75pt, includehead=true, includefoot=true}

---

... (some chunks of code go here)

\fancyhead[L]{\includegraphics[width=4cm]{example-image-duck}}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage} \\ \today}
\fancyfoot[L]{Identification Report \\ User generating the report: }

\vspace*{1\baselineskip}

# IDENTIFICATION REPORT

(some more LaTex and code chunks follow, including bar plots and KableExtra tables)

...

推荐阅读