You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在RMarkdown的PDF输出中设置图片为标题页

解决RMarkdown生成PDF时的标题页问题

针对你遇到的两个问题,直接修改代码就能搞定:

问题1:将标题页图片设为PDF首页

原代码里的include-before: '\newpage{}{=latex}'会在文档开头自动插入空白页,删掉这行配置,就能让图片页成为真正的首页。同时把图片后的\\newpage换成LaTeX原生的\newpage,确保图片页后正确分页,目录从下一页开始显示。

问题2:移除标题页的页眉与页码

在插入标题页图片前添加\thispagestyle{empty}命令,这个命令会强制当前页面(标题页)不加载任何页眉和页码。另外把\pagestyle{fancy}的设置移到标题页之后,确保自定义页眉页脚只从目录和正文开始生效。

修改后的完整代码

---
title: "Title of my report"
author:
- Steve Example
date: "`r format(Sys.Date(), '%d.%m.%Y') `"
output:
  pdf_document:
    toc: yes
    toc_depth: 3
    number_sections: yes
toc-title: Content
fontsize: 10pt
lang: de
documentclass: scrreprt
classoption: oneside
header-includes: 
  - \usepackage{helvet} 
  - \usepackage{fancyhdr} 
  - \usepackage[font={small}]{caption}
  - \usepackage[a4paper, total={6in, 9in}]{geometry}
  - \renewcommand\familydefault{\sfdefault}
  - \AtBeginDocument{\let\maketitle\relax}
---

\thispagestyle{empty}
![](titlepage.jpg)
\newpage

\pagestyle{fancy}
\fancyhead{} 
\fancyhead[L]{My University\\ \textbf{IDR} Institute for difficult LaTeX-Reports}
\fancyfoot[C]{\thepage} 

\let\oldsection\section

# First section

## Sub-section
## Another sub-section

# Second chapter

## Sub-section
## Another sub-section

关键修改说明

  1. 移除YAML中的include-before配置,消除首页前的空白页
  2. \thispagestyle{empty}紧跟文档开头,确保标题页应用空样式
  3. 用LaTeX原生的\newpage替代\\newpage,保证分页逻辑正确
  4. 将\pagestyle{fancy}移到标题页之后,避免自定义页眉页脚影响标题页

内容的提问来源于stack exchange,提问作者D. Studer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 21:32:07