I would like to add an artistic watermark image on every page, at a random location on each page. I am considering the eso-pic package, but am open to just about any suggestion.

Does anyone have any idea how to achieve the above, given the following...

  1. The Random Placement, Doesn't have to be 'Strictly' random as per strict mathematical standards, and could be based on system clock millisecond value or the like, just sufficiently random so as to appear random to the reader.
  2. The size of the image may vary, and, also, the size of the paper may vary.
  3. I have the image generation handled, for the purposes of this post, just assume it is a .jpg or .bmp etc...

I am sure some of you may have seen financial reports, or Information memorandums and the like, quite often a watermark varies slightly per page....

UPDATE: I probably should have said, the pictures are created on the fly at compile time. They should be different for every page.

In terms of providing MWA, this is an example of what I have done so far. Note, this working example uses R, and knitr (http://yihui.name/knitr/) to access ggpplot2 objects directly as they are created in the R environment. By using tikz device, the benefits of LaTeX can be applied, although not exploited in this example, in the sense that math formatting can be applied to axis labels, and other labels of such nature. In terms of this query, the impetus comes from a desire to plot mathematical functions for watermarks, one can imagine a wave function propagating one page at a time.

[Note: Incidentally, you may identify that when typeset, the knitr code chunks contained aren't being re-evaluated each time they are called (they are referring to a cached copy of the first evaluation), and I have posted a query on the knitr homepage to have this resolved if possible]

In order to compile this, the file needs to be saved with .Rnw extension (as opposed to .tex), and executed with the following command.

"C:/Program Files/R/R-2.15.2/bin/Rscript.exe" -e "knitr::knit2pdf('%.Rnw')"

[Note: the above command can be added as a user command in TexMaker or whatever your particular flavor of editor is, obviously, change the directory to suit your own R installation.]

Standard Preamble as Follows. Nothing Special.


\title{The Quick Brown Fox}
\author{Joe Bloggs}

The following section is also in the preamble, and defines chunks as per knitr functionality. The code inside the <<>>= and @ flags, refers to code executed in R. There are many many options which can be parsed into each chunk. Too many to explain here, however, I encourage people to refer to the knitr website as listed above.

%Load the Packages. 
<<setting_load_knitr,cache=TRUE,eval = TRUE,echo = TRUE,include=FALSE>>=
    ## Install latest version of tikzDevice (Installation Currently Disabled)
    ## install.packages("tikzDevice", repos="http://R-Forge.R-project.org")

    ## Default Message Suppression - Spam Sucks.
    suppressMessages( library(knitr))

    ##Stating Minimum Requirements.

Define the chunk to plot the object.

%Define the Plot Block.
    suppressMessages( library(ggplot2))
    theme_new <- theme_set(theme_bw(0)) 
    x <- runif(1:250)  #250 random points.
    y <- runif(1:length(x)) #create corresponding y values
    z <- c(1:length(x)) #increasing point sizes
    zf <- as.factor(1:length(x))
    dat <- data.frame(x,y,z,zf)

    ##Plot the items.
    ggplot(dat,aes(x,y)) + 
        geom_point(aes(size = z,color=zf),alpha=0.33) +
        scale_x_continuous(element_blank()) +
        scale_y_continuous(element_blank()) +

The next part of the preamble defines function to draw the plot within the LaTeX environment, calling the above chunk, adding to every shipout as per the eso-pic package.

%Define the command to call on each page.
    <<ref.label='background_plot', dev='png', out.width='1.5\\paperheight',out.height='1.5\\paperheight',echo=FALSE,dpi=500>>=

Now to create the MWE dummy document.

    %Dummy Section 1
    \section{Lorem Ipsum}

    %Dummy Section 2
    \section{Lorem Ipsum}

    %Dummy Section 3
    \section{Lorem Ipsum}

So in terms of this question. The example above creates a series of randomly placed pretty circles. The size of the image generated is much larger than the actual page, by randomly shifting it left and right, up and down, no one page will be the same, hence the objective of this query.

Example output: Example Output

As another example output, (this time used in a letter template), the use of equations for watermark as per the following code:

    suppressMessages( library(ggplot2))
    theme_new <- theme_set(theme_bw(0)) 
    x <- seq(-1.25,0.5,0.005) #define x data
    f1 <- function(x)sin(x) #define functions
    f2 <- function(x)((2*pi)^(-0.5))*exp(-(x*x)/2) #Gaussian function
    f3 <- function(x){f1(8*x)*f2(x)} ##Gaussian Wavepacket net function.

    ##Create the dataframe.
    df <- data.frame(x=x,GaussUpp=f2(pi*x),WavePacket=f3(pi*x))
    df.melt <- melt(df,id.vars = c('x'))
    colnames(df.melt) <- c('X','Function','Value')

    ##Now Plot, different colors for the different plots.
    ggplot(df.melt,aes(x=X,y=Value)) +
        geom_path(size= 8,aes(color=Function),alpha=0.025)+
        geom_path(size= 4,aes(color=Function),alpha=0.025)+ 
        geom_path(size= 2,aes(color=Function),alpha=0.025)+ 
        geom_path(size= 1,aes(color=Function),alpha=0.025)+ 
        scale_x_continuous(element_blank()) +
        scale_y_continuous(element_blank()) +

Yielded the following result...

Second Example

Tweaking some of the settings in the Plotting function can yield a completely different look and feel

Third Example

  • Also see the LuaTeX manual.
    – user10274
    Dec 20, 2012 at 13:51
  • 2
    See also here: tex.stackexchange.com/questions/35133
    – mbork
    Dec 20, 2012 at 16:08
  • 4
    I may not have been very clear. What I meant is that the LuaTeX manual has a nice example of an incremental watermark: the moon circling the earth (around a common centre of gravity:-).
    – user10274
    Dec 21, 2012 at 8:05
  • So out of the 196 pages in the LuaTex manual, would you be so kind as to state where the reference material is relating to the above? Dec 21, 2012 at 8:42

1 Answer 1


May be I did not understand fully. But this may be one (worth) try using background package from Gonzalo Medina:

contents={\begin{tikzpicture}[remember picture,overlay]
 \node[draw=none] at ($(current page.south west) + (2in+rnd*.8\textwidth,2in+rnd*.8\textheight)$) {
  • Thanks, Harish please see update to original question, re the pictures. Dec 20, 2012 at 15:07
  • @ADP You said you handled picture generation. It will be nice of you if you could post the code you have managed so far. Pl. make it from \documentclass{article}.....\end{document}. We call it MWE. `:-)
    – user11232
    Dec 20, 2012 at 15:14
  • Sure, but it will have to be tomorrow, I'm committed till then. Dec 20, 2012 at 15:41
  • MWE has been added.... Dec 21, 2012 at 7:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .