8

I'm trying to show the watermark as a background layer so the reader may have the option to either see the background or not. I'm using the LuaLaTeX and the xwatermark package. When I compile the script neither the background appears nor the layer. Here's a MWE of my script:

\documentclass[12pt,a4paper]{report}

\usepackage[no-math]{fontspec}
    \setmainfont{ArnoPro-Regular}

\usepackage{polyglossia}
    \setdefaultlanguage{english}
    \disablehyphenation

\usepackage[
    hmarginratio = 1:1,
    left = 3cm,
    right = 2cm,
    top = 3cm,
    bottom = 2cm,
    headheight = 15pt
    ]{geometry}

\usepackage{amsmath, amsthm, amssymb, amsfonts}

\usepackage[table]{xcolor}
    \definecolor{rowgrey}{rgb}{.9,.9,.9}
    \definecolor{heavengreen}{rgb}{.8901,.9568,.8941}
    \definecolor{greeen}{HTML}{7cc576}
    \definecolor{gold}{HTML}{f9ad81}
    \definecolor{smoofie}{HTML}{fff7ea}

\usepackage{pgfcore}
\usepackage[printwatermark,watermarkparser=|]{xwatermark}

\usepackage{tikz}
    \usetikzlibrary{backgrounds}

\usepackage{afterpage}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage[tikz]{ocgx2}

\begin{document}

\begin{titlepage}
    \pagecolor{smoofie}\afterpage{\nopagecolor}
    \begin{center}
        \vspace*{4cm}
        \begin{tikzpicture}
            \draw[line width=2mm,draw=greeen] (0,0) circle (4cm);
            \draw[line width=2mm,draw=gold] (0,0) circle (2cm);
        \end{tikzpicture}
    \end{center}
\end{titlepage}

\begin{ocg}{Background}{background}{true}
    \newwatermark[pages=1-5,angle=0,scale=2,xpos=0cm,ypos=0cm]{%
        \begin{tikzpicture}[opacity=.2]
            \fill [heavengreen] (-12,-5) rectangle (7,15);
            \draw[line width=2mm,draw=greeen,fill=heavengreen] (0,0) circle (4cm);
            \draw[line width=2mm,draw=gold] (0,0) circle (2cm);
        \end{tikzpicture}%
    }
\end{ocg}

\sloppy

\lipsum[1-12]

\end{document}
3
  • 1
    Probably the layer should be defined inside the watermark, not the other way round: \newwatermark[...]{\begin{ocg} ... \end{ocg}} – Robert Jun 3 '18 at 16:16
  • It worked just for the first page. The following ones show the background but not the option to deactivate the layer. – Levy Jun 3 '18 at 16:25
  • Okay, now it's fully functional! Thank you very much. – Levy Jun 3 '18 at 16:27
11

The layer should be defined inside the watermark, not the other way round:

\newwatermark[pages=1-5,angle=0,scale=2,xpos=0cm,ypos=0cm]{%
    \begin{ocg}{Background}{background}{true}%
        \begin{tikzpicture}[opacity=.2]
            \fill [heavengreen] (-12,-5) rectangle (7,15);
            \draw[line width=2mm,draw=greeen,fill=heavengreen] (0,0) circle (4cm);
            \draw[line width=2mm,draw=gold] (0,0) circle (2cm);
        \end{tikzpicture}%
    \end{ocg}%
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.