第一页和其他页面上的标题

use*_*875 5 r r-markdown

使用fancyhdr为2+页创建了页眉,但是如何使相同的页眉也出现在首页上?

这是rmarkdown:

---
title: "Untitled"
classoption: landscape
output: 
  pdf_document:
    number_sections: false
    dev: pdf
    keep_tex: false
    toc: yes
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[C]{center text}
- \fancyhead[R]{right text}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Run Code Online (Sandbox Code Playgroud)

alk*_*989 8

包含\thispagestyle{fancy}在文档的开头(例如,紧接在 yaml 标头之后)以使首页更加美观。

在此输入图像描述

编辑以解决您的评论

如果您想在第一页中使用不同的中心文本,则可以在定义时使用 if\fancyhead

\fancyhead[C]{\ifnum\value{page}>1 center text \else \fi}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述