问题描述
我想为我的页脚添加背景颜色,如下所示。
我没有得到添加到页脚的背景颜色,但它不起作用。下面的代码只生成页脚。如何获得如上所示的输出制作背景色
---
title: "123"
output:
pdf_document:
keep_tex: true
classoption: svgnames
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead{}
- \fancyfoot{}
- \lfoot[LE,LO]{ABCDEFGHIJ 2020 1.3.4}
- \fancypagestyle{plain}{\pagestyle{fancy}}
---
解决方法
使用 tikz 在页脚中添加彩色框的快速方法:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\lfoot[LE,LO]{\tikz{\node[white,outer sep=0pt,inner sep=10pt,fill=blue!70,text width=\dimexpr\textwidth-20pt\relax,align=left] at (0,0) {ABCDEFGHIJ 2020 1.3.4};}}
\setlength{\footskip}{30.44pt}
\fancypagestyle{plain}{\pagestyle{fancy}}
\begin{document}
text
\end{document}
或在 rmarkdown 中:
---
title: "123"
output:
pdf_document:
keep_tex: true
classoption: svgnames
header-includes:
- \usepackage{tikz}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead{}
- \fancyfoot{}
- \lfoot[LE,0) {ABCDEFGHIJ 2020 1.3.4};}}
- \setlength{\footskip}{30.44pt}
- \fancypagestyle{plain}{\pagestyle{fancy}}
---
test
(使用 tikz 进行这项工作的优点是调整文本周围的填充变得非常容易)
,您可以使用 LaTeX 代码。下面是一个例子:
---
title: "Untitled"
author: "bttomio"
date: "5/1/2021"
output: pdf_document
header-includes:
- \usepackage{xcolor}
---
```{r setup,include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an example^[\textcolor{white}{\colorbox{blue}{Example in a R Markdown document.}}]
-输出