使用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.
最佳答案
包含 \thispagestyle{fancy}
在文档的开头(例如,在 yaml 标题之后)使第一页看起来很漂亮。
编辑以解决您的评论
如果你想在第一页有不同的中心文本,你可以在定义 \fancyhead
时使用 if
\fancyhead[C]{\ifnum\value{page}>1 center text \else \fi}
关于r - 第一页和其他页的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57981868/