【问题标题】:Watermark in rmarkdownrmarkdown 中的水印
【发布时间】:2015-12-21 06:47:53
【问题描述】:

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

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

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

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

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

\newpage

\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()
```

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

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

【问题讨论】:

  • 查看cowplot包。
  • 如果您需要标记为您自己的东西,您可以将版权文本添加到违规情节本身,这样可以保护您免受屏幕限制。
  • 我在cowplot中看到了注释,但真的想避免每个图表都带有注释。我想我可以将它分配给一个变量,但我真的很想在文档中有一个地方可以打开/关闭水印。

标签: r latex knitr r-markdown watermark


【解决方案1】:

尝试使用

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

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

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

这应该在页面的ForeGround(顶部)中添加一个旋转的草稿消息(半透明)。

【讨论】:

  • 这太棒了。谢谢!只有一个问题。我为此示例进行了简化,但通常我使用in_header: header.tex 来存储我的 tex 包含和函数。我目前只有\blandscape\elandscape 来启动和停止风景。我尝试将您的代码作为一个名为\markasdraft 的新函数添加到我的header.tex,它可以工作,但它只适用于单个页面。知道如何使它作为我可以用一行调用的函数来工作吗?在下一条评论中粘贴我的 header.tex。
  • \usepackage{lscape} \usepackage{eso-pic,graphicx,transparent} \newcommand{\blandscape}{ \begin{landscape} \pagebreak[4]\global\pdfpageattr\expandafter{\the \pdfpageattr/Rotate 90}} \newcommand{\elandscape}{ \end{landscape} \pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 0}} \newcommand{\markasdraft}{ AddToShipoutPictureFG{ \ AtPageCenter{% 或 \AtTextCenter \makebox[0pt]{\rotatebox[origin=c]{45}{% \scalebox{5}{\texttransparent{0.3}{DRAFT}}% }} } } }
  • @JohnTarr:您似乎缺少\。通过调用\markasdraft,它应该从该点向前激活草案。否则,如果您只希望它用于单个页面,那么可以使用\AddToShipoutPictureFG*(加星标的版本)。
  • 已确认。这是缺少的反斜杠。再次感谢。现在我也可以拨打\markconfidential等电话。
猜你喜欢
  • 2021-03-06
  • 1970-01-01
  • 1970-01-01
  • 2010-10-09
  • 2016-12-01
  • 1970-01-01
  • 2021-02-19
  • 2018-03-21
  • 1970-01-01
相关资源
最近更新 更多