我知道如何在 LaTeX 报告中的整页上使用水印,例如使用以下代码:
\usepackage{draftwatermark}
\SetWatermarkText{Confidential}
\SetWatermarkScale{5}
但是,我想在我的报告中使用水印仅有的在我包含的图片/图形上,这样文本就不会被任何东西遮住。只有图片才应该标有例如“机密”字样。
答案1
尝试雙水印包。它允许您指定水印的位置(在页面上) - 适用于图形和文本。
\documentclass{article}
\makeatletter
\usepackage[dvipsnames]{xcolor}
\usepackage[colorlinks,pdfview=FitB]{hyperref}
\usepackage[printwatermark]{xwatermark}
\thispagestyle{empty}
% Local watermark locations:
\watermarkpaths{{./}{./Graphics/}}
% One combined watermark (graphics + text). This is what you need. The key
% to note here is 'textontoppic':
\newwatermark[
oddpages,coordunit=pc,fontfamily=put,textcolor=red,
fontsize=2cm,textalign=center,textangle=29,picangle=0,
textxpos=-1,textypos=1,picxpos=0,picypos=0,
textontoppic,picbb=20 21 590 400,
picscale=.6,picfile=comet1,picfileext=pdf
]{Confidential}
% Repeated combined watermark (graphics + text):
\xwmgetpicturesize[scale=.5,viewport=20 21 590 400]{comet1}
\def\twidth#1{.5\paperwidth#1\widthofpic}
\def\theight#1{.5\paperheight#1\heightofpic}
\repeatwatermarks[Page=\thepage]{%
oddpages,coordunit=pc,picbb=20 21 590 400,picscale=.5,picfile=comet1,
textontoppic,fontsize=2.5cm,textcolor=white
}{%
picxpos=-\twidth{+}/2,picypos=-\theight{+}/2,
textxpos=-\twidth{+}/2,textypos=-\theight{+}/2;
picxpos=-\twidth{+}/2,picypos=\theight{-}/2,
textxpos=-\twidth{+}/2,textypos=\theight{-}/4;
picxpos=\twidth{-}/2,picypos=-\theight{+}/2,
textxpos=\twidth{-}/2,textypos=-\theight{+}/2;
picxpos=\twidth{-}/2,picypos=\theight{-}/2,
textxpos=\twidth{-}/2,textypos=\theight{-}/4
}
\makeatother
\begin{document}
xx
\end{document}
\newpage
yy
\newpage
zz
\newpage
aa
\newpage
bb
\end{document}
答案2
获取一些代码调整超出页边距的大图像的大小,同时保留现有比例,重新定义\includegraphics
可以在所有图像上放置“保密声明”,或者有选择地排除声明:
\documentclass{article}
\usepackage{xparse,graphicx,xcolor}% http://ctan.org/pkg/{graphicx,xcolor}
\newcommand{\confidential}{\color{red!80}\LARGE\bfseries CONFIDENTIAL}% Confidentiality notice
\newsavebox\IBox
\let\IncludeGraphics\includegraphics
\RenewDocumentCommand{\includegraphics}{s O{} m}{%
\sbox\IBox{\IncludeGraphics[#2]{#3}}%
\ooalign{\usebox\IBox% Print graphic
\IfBooleanTF{#1}{}{% Confidential or not
\cr\hss%
\raisebox{.1\ht\IBox}{\resizebox{.8\wd\IBox}{.8\ht\IBox}{\confidential}}% Print confidentiality notice
\hss}}}%
\begin{document}
\includegraphics[width=20pt]{example-image-a}
\includegraphics[height=30pt]{example-image-b}
\includegraphics[width=10em,height=10em]{example-image-c}
\includegraphics*[scale=.2]{example-image-a}
\renewcommand{\confidential}{\color{green!70}\rule{10pt}{10pt}}% Change confidentiality notice
\includegraphics[width=15ex]{example-image-b}
\end{document}
xparse
提供修改版的界面\includegraphics
。现在它提供了一个带星号的变体\includegraphics*
,用于打印图像没有一份“保密通知”。
“保密声明”位于中央,并被拉伸以适应图像高度/宽度的80%以上。