调整 PDF 输出中的 R Markdown 标题位置

Adjusting R Markdown Title Position in PDF output

我正在创建 R Markdown 报告,但找不到将我的标题下移到页面下方的方法。

这是一个最小的例子,我想将标题向下移动 5 厘米:

---
title: "This is my title to display at 5cm below the top"
output:
  pdf_document:
    includes:
      in_header: header.tex
---

\thispagestyle{titlepage}

header.tex 文件包含一些自定义样式:

\usepackage{fancyhdr}
\fancypagestyle{titlepage}{
    \fancyfoot[LE,RO]{\thepage\ of \pageref{LastPage}}
    \fancyfoot[LE,LO]{Project}
    \fancyhead[L]{\includegraphics[width=4cm]{logo.png}} 
    }

输出

请注意,我不是在谈论边距,只是想移动标题,使其不会始终位于页面顶部。

这样做就可以了:

\setlength{\headsep}{5cm}
\thispagestyle{title page} 

另一种选择是使用 titling LaTeX 包,它可以轻松更改标题的样式。我在 YAML 的 header-includes 参数中包含了一些内联定制:

---
title: "This is my title to display at 5cm below the top"
output: pdf_document
header-includes:
  - \usepackage{titling}
  - \setlength{\droptitle}{5em} 
---

# Content
And then something here...

\newpage

# Next Page
Some more text

Including the LaTeX commands in the YAML is generally okay for small edits like this, but if you want to make further customisations I would recommend keeping them in an a separate .tex file as explained in the R Markdown Definitive Guide