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

时间:2019-09-17 20:48:34

标签: 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.

1 个答案:

答案 0 :(得分:4)

在文档的开头(例如,在yaml标头之后)添加\thispagestyle{fancy},以使第一页看起来很漂亮。

enter image description here

编辑以发表您的评论

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

\fancyhead[C]{\ifnum\value{page}>1 center text \else \fi}

enter image description here