本文介绍了rmarkdown 中的水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我研究并发现了如何在 rmarkdown 文档中创建水印.

I have researched and found how to create a watermark in an rmarkdown document.

它在基本文本上效果很好,但是当你有一个情节沉重的页面时,它会隐藏在情节后面.

It works great on basic text, but when you have a plot heavy page, it gets hidden behind the plot.

显然,这使某人可以轻松截屏并在 PDF 之外使用它们.

Obviously, this makes it easy for someone to screencap the figures and use them outside of the PDF.

下面是一些清楚地说明问题的代码.

Below is some code that demonstrates the issue clearly.

---
title: "Testing Watermark"
author: "John"
date: "September 18, 2015"
header-includes:
   - usepackage{draftwatermark}
output:
  pdf_document
---

This is some basic text.
Note the watermark on this page, and the hidden watermark on the next page.


ewpage

SetWatermarkText{DRAFT}

```{r echo=FALSE, warning=FALSE, message=FALSE, fig.height=7}
library(ggplot2)

ggplot(mtcars) +
  geom_point(aes(mtcars$mpg, mtcars$cyl)) +
  facet_wrap(~carb, ncol=1) +
  theme_bw()
```

如果有人知道解决此问题的方法,我将不胜感激.

If anyone is aware of a fix for this, I'd be grateful.

就我而言,要么使 ggplot 背景透明(我尝试过),要么将水印带到前景并使其透明.

Either making the ggplot backgrounds transparent (which I've tried), or bringing the watermark to the foreground and making it transparent would be ok as far as I'm concerned.

推荐答案

尝试使用

header-includes:
   - usepackage{eso-pic,graphicx,transparent}

然后在文档的第一页(在 LaTeX 部分中)添加

and then on the first page of your document (within the LaTeX part), add

AddToShipoutPictureFG{
  AtPageCenter{% or AtTextCenter
    makebox[0pt]{
otatebox[origin=c]{45}{%
      scalebox{5}{	exttransparent{0.3}{DRAFT}}%
    }}
  }
}

这应该在页面的 ForeG 圆形(顶部)中添加一个旋转的 DRAFT 消息(半透明).

This should add a rotated DRAFT message (semi-transparent) in the ForeGround (over top) of the page.

这篇关于rmarkdown 中的水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 04:34