首页 > 解决方案 > 在 LaTeX R-Markdown 中遇到 \headheight 问题(页面布局不一致)

问题描述

我目前在 Rmarkdown 中遇到乳胶问题(使用 fancyhdr 包)。我正在尝试制作具有某种模板样式的数据报告。但截至目前,我的每一页的标题 1 都没有正确对齐。我认为它与我的 \headheight 有关,但我不确定如何解决它。

目前这是在 R-markdown 中完成的,我非常有信心这个问题与我的 YAML 有关。如果有人能告诉我如何修复我的 YAML 编码 \headheight 或整体改进我的 YAML 编码以解决重叠问题,我将不胜感激。

运行此代码时没有错误,但这是它们提供给我的警告(但我不知道如何解决警告)

Package Fancyhdr Warning: \headheight is too small (12.0pt): 
 Make it at least 32.08571pt.
 We now make it that large for the rest of the document.
 This may cause the page layout to be inconsistent, however. 

这是我的 YAML:

---
output: 
  pdf_document:
    latex_engine: pdflatex
header-includes:|
  \usepackage{graphicx}
  \usepackage{fancyhdr}
  \pagestyle{fancy}
  \newcommand{\helv}{%
    \fontfamily{phv}\fontseries{b}\fontsize{9}{11}\selectfont}
  \fancyhead[R]{\includegraphics[width=3cm]{logo.png}}
  \fancyhead[L]{\textbf\selectfont\sffamily{Daily Report}}
  \fancyfoot[L]{\textbf\selectfont\sffamily{NOT INTENDED FOR FORWARDING}}
  \renewcommand{\headrulewidth}{0.4pt}
  \renewcommand{\footrulewidth}{0.4pt}
classoption: a4paper
---

这些在其余的代码中:

```r-markdown

## \selectfont\sffamily{EQUITY 1}

# content page 1 

\newpage

## \selectfont\sffamily{EQUITY 2} 

# content page 2 

我在 TeXStackExchange 上发布了 pdf 输出的图像:https ://tex.stackexchange.com/questions/482525/having-problems-with-latex-coding-in-rmarkdown-fancyhdr-headheight

我希望所有这些都相互对齐。我不知道我是否在 YAML 中正确完成了编码。

标签: rlatexr-markdownpdflatex

解决方案


警告非常明确,头部高度需要大于 32.08571pt。\setlength{\headheight}{32.09pt}可以通过将例如添加到您的标头包含来满足此要求。

---
output: 
  pdf_document:
    latex_engine: pdflatex
header-includes:|
  \usepackage{graphicx}
  \usepackage{fancyhdr}
  \pagestyle{fancy}
  \newcommand{\helv}{%
    \fontfamily{phv}\fontseries{b}\fontsize{9}{11}\selectfont}
  \fancyhead[R]{\includegraphics[width=3cm]{logo.png}}
  \fancyhead[L]{\textbf\selectfont\sffamily{Daily Report}}
  \fancyfoot[L]{\textbf\selectfont\sffamily{NOT INTENDED FOR FORWARDING}}
  \renewcommand{\headrulewidth}{0.4pt}
  \renewcommand{\footrulewidth}{0.4pt}
  \setlength{\headheight}{32.09pt}
classoption: a4paper
---

推荐阅读