【问题标题】:My footer disappears after the first page (but not the header!) in R-Markdown我的页脚在 R-Markdown 的第一页(但不是页眉!)之后消失了
【发布时间】:2019-12-09 23:02:10
【问题描述】:

我在 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下面。结果是一样的。页脚在第一页上正确生成,仅此而已,而页眉出现在每一页的开头。

知道会发生什么吗?

【问题讨论】:

  • 你能截取生成的 .tex 文件吗?
  • 你能把 Rmd 缩小到 minimal reproducible example 吗?可以通过output.pdf_document.keep_tex: yes 拦截@samcarter 要求的.tex 文件。
  • @samcarter 当我尝试执行一个最小的可重现示例时,我发现了一些东西。它是产生冲突的标头。如果我不使用 \includegraphics 而是将所有内容替换为一个字符(“Hello”),那么页眉和页脚都会出现在所有页面上。所以肯定是和header中的图片上传有关。
  • @MarcBF 我怀疑是headheight的问题,但我需要一个小的tex文档来测试。您是否在 .log 文件中收到任何有关 headheight 的警告?
  • @MarcBF 你能显示 tex 文件吗?

标签: latex markdown r-markdown pdflatex


【解决方案1】:

您的标题远高于默认的\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)

...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-11
    • 1970-01-01
    • 2018-07-15
    • 1970-01-01
    相关资源
    最近更新 更多