r - 第一页和其他页的标题

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

最佳答案

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

enter image description here

编辑以解决您的评论

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

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

enter image description here

关于r - 第一页和其他页的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57981868/

相关文章:

r - 使用外部提供的指标数据进行 quantstrat

r - 禁用鼠标单击以在 rmarkdown slidy_presentation 中显示另一张幻灯片

html - 为什么 html 中 visnetwork 的图表布局太小

r - 如何对齐多行标题

r - 使用 KnitR 在 R 中以编程方式创建 Markdown 表

R Markdown : Citation parsing

r - 将使用 Markdown 语法编写的文本文件嵌入到另一个 RMarkdown 文件中

R数据.表: efficiently access and update a variable column name in j expression with grouping

r - R数据颜色的主成分分析

r - 如何反转绘图上的 y 轴