Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to add a draftwatermark to my document, but I'm having some problems with lstlisting.

Whenever I've used lstlisting (for C++ code), the background of the code section is white and overwrites (draws?) the Draft in the background.

I've seen you can change the background colour of the lstlisting, but I haven't been able to find a way to set it to transparent.

What would be the best way of dealing with this?

share|improve this question

1 Answer 1

up vote 4 down vote accepted
  • Do not use option backgroundcolor for the listings, if you do not want the background color. backgroundcolor={} clears a previously set background color.

  • If you are using pdfTeX in PDF mode, then package transparent can be used for transparency.

The following example uses page color as simplified draft watermark:

\documentclass{article}
\usepackage{listings}
\usepackage{color}
\usepackage{transparent}
\pagecolor{yellow}
\begin{document}
\section{Hello World}
\begin{lstlisting}[backgroundcolor=\transparent{.5}\color{red}]
Hello World
\end{lstlisting}
\end{document}

Result: The red code background becomes orange:

Result

share|improve this answer
1  
I would aslo advise to add the line \pdfpageattr {/Group << /S /Transparency /I true /CS /DeviceRGB>>} before your \documentclass{} as otherwise adobe reader will not display pages with transparency properly (very ragged fonts with no anti-aliasing) –  ArTourter Jan 17 '13 at 15:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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