我有一些自定义颜色,我想让标题fancyhdr
有不同的颜色。
如何让不同的标题、、\fancyhead[L]
具有不同的颜色框和字体颜色?如何让它们具有不同的字体大小?\fancyhead[R]
\fancyhead[C]
\fancyhead[R]
谢谢。
以下是我目前拥有的:
---
title: "Untitled"
classoption: landscape
output:
pdf_document:
number_sections: false
dev: pdf
keep_tex: false
toc: yes
header-includes:
- \usepackage{fancyhdr}
- \usepackage{etoolbox}
- \usepackage{color}
- \pagestyle{fancy}
- \definecolor{col1}{RGB}{7, 252, 3}
- \definecolor{col2}{RGB}{7, 200, 3}
- \fancyhead[L]{%
\colorbox{col1}\color{blue}{left}%
}
- \fancyhead[R]{%
\colorbox{col2}\color{red}\fontsize{12?}{right}%
}
- \fancyhead[C]{ % \colorbox{col2}\color{white}\nouppercase{\leftmark} % }
- \let\oldheadrule\headrule
- \renewcommand{\headrule}{\color{col2}\oldheadrule}
---
```{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)
```
\newpage
# 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.
\newpage
# page 3
You can also embed plots, for example:
```{r pressured, 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
\colorbox{<colour>}{<stuff>}
需要两个参数。第一个是<colour>
,而第二个是<stuff>
包含在框内的 。使用- \fancyhead[L]{% \colorbox{col1}\color{blue}{left}% }
错误地将
\color
作为第二个参数放入\colorbox
,这没有意义。您需要使用类似- \fancyhead[L]{\colorbox{col1}{\color{blue}left}}
还请注意使用单行而不是换行;
header-includes
在 Markdown 中编写标题内容(通过)的翻译方式与您想象的方式不同。要更改字体大小,请使用
\fontsize{<size>}{<baseline skip>}\selectfont
。对于你的情况,类似下面的命令\fontsize{12}{14}\selectfont
就可以了。
您可能会收到有关标题高度太小的警告。为此,请添加
- \setlength{\headheigh}{<height>}
以满足您的需求(<height>
至少与建议的高度一样大)。