About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Latest news 2024-10-15: New blog post: Tales for Our Times Book Launch.


6.4.2 Watermarks

[`Watermarks' on every page] There are a number of packages that enable you to place some text (such as “CONFIDENTIAL” or “DRAFT”) across the background of every page. In addition to these packages, the pdftk application described in §2.3 Security, can also be used for this purpose. CTAN has several topics that cover this area: watermark, background and decoration. This section will only discuss two packages: xwatermark (which extends the draftmark and watermark packages) and background. The background package is simpler to use. The xwatermark package is more flexible.


6.4.2.1 The background Package

The background package [56] provides a way of specifying a watermark using the tikz package (part of the pgf bundle [102]). By default, the package will use the word “Draft” as a watermark, but this can be changed. Options can either be set via the package option list or via:

\backgroundsetup{options}

where ⟨options⟩ is a key=value list. The background package requires two LaTeX calls during the document build. Available options are:

pages
This key specifies whether the watermark should appear on all or some of the pages. Available values are: all or some. If the value some is specified, you must use the command \BgThisPage on the pages where the watermark is required. If the value all is specified, you can use the command \NoBgThisPage on the pages where you don't want a watermark. (Don't use this command in two-column mode.)

firstpage
This is a boolean key. If true, the watermark only appears on the first page. (The default is false.)

placement
This key specifies the placement of the watermark and may take one of the values: center (default), top or bottom.

contents
This key specifies the material used for the watermark. The value may be just text (such as “Confidential”) or an image included using \includegraphics. If the value of this key contains commands, the key may only be used within \backgroundsetup not as a package option.

color
The watermark colour. (The background package automatically loads the xcolor package [41].)

angle
This key specifies the angle of rotation.

opacity
This key indicates the transparency. The value may be a number from 0 (full transparency) to 1 (no transparency). Note that PostScript doesn't support transparency, so if you use latex and dvips, the watermark won't show any transparency in the PostScript file.

scale
This key specifies the scale factor.

position
This key can be used to adjust the position of the watermark. The value should be in TikZ coordinate form (see the pgf manual [102]).

anchor
This key specifies the TikZ anchor for the watermark. (See the pgf manual [102].)

hshift
This key specifies the horizontal shift.

vshift
This key specifies the vertical shift.

Example 34. Watermarks (background package)

This example uses the lipsum package [33] to generate dummy text to pad out the document.

\documentclass[a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{background}
\usepackage{lipsum}

\backgroundsetup{contents={CONFIDENTIAL}}

\begin{document}

\lipsum[1-55]

\end{document}

The first page of this document is shown in Figure 6.4. You can download or view this example.

Figure 6.4: Sample Watermark (background package)
 
The page has the word CONFIDENTIAL written in faded-red across the text from the bottom left to the top right of the type block.


6.4.2.2 The xwatermark Package

The xwatermark package [60] provides a way of adding either text or graphics as watermarks in the background or foreground of selected pages. In most cases, more than one LaTeX run will be required on your document. You will also mostly need to load a colour package, such as xcolor [41]. The xwatermark package can also be used to tile marks across the page, but that option isn't covered here. See the xwatermark documentation for details.

There are a number of package options for xwatermark. Only a subset of them are listed here:

printwatermark
This is a boolean key that determines whether or not the watermarks should be printed. The default value is true.

picontoptext
This is a boolean key that determines whether the picture watermark should be placed on top of the text watermark where they occur on the same page. The default value is true.

showpagecenter
This is a boolean key that determines whether the centre of the paper should be shown with a marker. The default value is false.

disablegeometry
This is a boolean key. If true, this indicates that the page layout settings by the geometry package [110] should be disabled. The default value is false. (This option is less likely to be needed with newer versions of geometry.)
See the xwatermark package documentation for details of the other package options.

A new watermark is defined using:

\newwatermark[options]{mark}

where ⟨mark⟩ is the watermark text. This may be empty if you want an image for the watermark. There is a starred variant of this command that puts the watermark in the foreground instead of the background. There is also a prime variant, but that's not covered here. See the xwatermark documentation [60] for further details.

The optional argument, ⟨options⟩, is a key=value list of options. For brevity, this section only covers a small subset of those options. See the xwatermark documentation for further details. The option list must contain the page or page set on which the watermark is to be displayed. The page specifier keys are as follows:

allpages
This key doesn't have a value. It indicates that the watermark should be displayed on all pages.

oddpages
This key doesn't have a value. It indicates that the watermark should be displayed on all odd pages.

evenpages
This key doesn't have a value. It indicates that the watermark should be displayed on all even pages.

firstpage
This key doesn't have a value. It indicates that the watermark should only be displayed on the first page.

lastpage
This key doesn't have a value. It indicates that the watermark should only be displayed on the last page.

page
The value of this key should be a page number to indicate that the page on which the watermark should be display. For example, page=4 indicates that the watermark should be displayed on page 4.

pages
The value of this key should be a range in the form n⟩-⟨m to indicate that the watermark should be displayed on pages ⟨n⟩ to ⟨m⟩, inclusive. For example, pages=4-10 indicates that the watermark should be displayed on pages 4 to 10.

pagex
The value of this key should be a comma-separated list of page numbers on which the watermark should be displayed. For example, pagex={1,3,7} indicates that the watermark should be displayed on pages 1, 3 and 7.

The text for the watermark may also be specified in ⟨options⟩ using the textmark={mark} key. The watermark can be scaled, rotated or translated using the following keys:

scale
The value of this key is the scaling factor.
angle
The value of this key is the angle of rotation.
xpos
The value of this key specifies the horizontal position of the watermark relative to the centre of the page.
ypos
The value of this key specifies the vertical position of the watermark relative to the centre of the page.
The formatting of the watermark can be adjusted using the following keys:
textalign
The value of this key indicates the horizontal alignment of the watermark and may be one of: center (default), left, right or justified.

fontfamily
The value of this key is the name of the font family (as supplied to \fontfamily). For example, fontfamily=pbk indicates Bookman.

fontseries
The value of this key is the name of the font series (as supplied to \fontseries). For example, fontseries=b indicates bold.

fontsize
The value of this key is the font size. The default is 1 cm.

textcolor
The value if this key is the colour of the watermark text.

If an image is required, the following keys specify the image file information:

picfile
The value of this key is the image filename. This should be in the same form as the mandatory argument of \includegraphics, so remember to use forward slashes for the directory divider even if you are building your document on a Windows operating system.

picfileext
The value of this key is the image file extension (such as pdf or png). Note that you have to use picfileext if you use picfile.

picscale
The value of this key is the scaling factor to apply to the image.

picangle
The value of this key is the angle of rotation to apply to the images.

There are other keys not covered here. See the xwatermark documentation [60] for further details.

Example 35. Watermarks (xwatermark package)

As with Example 34, this example uses the lipsum package [33] to generate dummy text to pad out the document.

\documentclass[a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{xcolor}
\usepackage{xwatermark}
\usepackage{lipsum}

\newwatermark[%
  allpages,% show on all pages
  fontfamily=pbk,% use Bookman font family
  angle=55,% rotate by 55 degrees
  scale=2.75,% scale by 2.75
  xpos=-1cm,% shift by 1cm to the left
  ypos=1cm% shift up by 1cm
]{SAMPLE WATERMARK}

\begin{document}
\lipsum[1-55]

\end{document}

The first page of this document is shown in Figure 6.5. You can download or view this example.

Figure 6.5: Sample Watermark (xwatermark package)
 
An image of the dummy text with SAMPLE WATERMARK written in faded-grey from the bottom left to the top right of the page.


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs