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.

What options are there to specify transparent colors, say the background in the example below? I thought xcolor would be able to do this but I can not find any reference to "alpha" or "transparency" in the manual.

\documentclass{article}
\usepackage{listings,xcolor}

\lstset{frame=shadowbox, backgroundcolor=\color{green}}

\title{Transparency test}

\begin{document}
\maketitle
\begin{lstlisting}
Hello, world.
\end{lstlisting}
\end{document}

Is it possible to do it with XeLaTeX or LuaLaTeX?

share|improve this question
    
Just a side note: in my experience, transparency does not render well in many PDF-readers, especially when printing. –  fheub Feb 24 '12 at 7:59
    
Pgf can do this, see section 84 (page 671 in my version) of the manual. I don't know if that is helpful in your case. –  Psirus Feb 24 '12 at 8:26
1  
@fheub: It's the printers to blame here, not the Readers. Transparency effects are a relatively new feature for PDF (≥ 1.4) and so far only few printers support it already. See tex.stackexchange.com/questions/40050/… for a discussion on the technical details. –  Daniel Feb 24 '12 at 15:00

3 Answers 3

I think you might be looking for transparent.

\documentclass{article}
\usepackage{color}
\usepackage{transparent}
\begin{document}
  \colorbox{red}{%
    Black text in a red box %
    \transparent{1.0}%
    \colorbox{blue}{%
      and now a blue box is added%
    }
  }

  \colorbox{red}{%
    Black text in a red box %
    \transparent{0.5}%
    \colorbox{blue}{%
      and now a transparent blue box is added%
    }
  }
\end{document}

enter image description here

share|improve this answer
    
But I can't see any difference in the example given in the documentation of the transparent package. –  Keks Dose Feb 24 '12 at 9:55
    
@KeksDose I added a mwe. –  StrongBad Feb 24 '12 at 13:04
    
Using xetex or luatex gives Package transparent Warning: Loading aborted, because pdfTeX is not running in PDF mode. –  Emre Feb 24 '12 at 23:59
    
@Emre I misread your question. I thought you were trying to do it with latex, but were willing to consider xetex or lautex. –  StrongBad Feb 26 '12 at 10:16

You can get transparency with the pgf package and it will work with xetex/luatex too. But opacity settings get lost at a pagebreak and TEX-groups and boxes are not respected (as far as I can see one of the point of the transparent package is to confine transparency to boxes). That means that the opacity can "leak out" if you don't reset it explicitly at the correct places:

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor,pgf}% http://ctan.org/pkg/{listings,xcolor,transparent}
\title{Transparency test}
\begin{document}
\maketitle
% Solid green
\lstset{frame=shadowbox, backgroundcolor=\color{green}}
\begin{lstlisting}
Hello, world.
\end{lstlisting}

% 50% transparent green
\lstset{frame=shadowbox, backgroundcolor={\color{green}\pgfsetfillopacity{0.5}}}
\begin{lstlisting}
Hello, world.
\end{lstlisting}


\lstset{frame=shadowbox, backgroundcolor=\color{green}}
\begin{lstlisting}
Hello, world.
\end{lstlisting}


\lstset{frame=shadowbox, backgroundcolor=\color{green}\pgfsetfillopacity{1}}
\begin{lstlisting}
Hello, world.
\end{lstlisting}

\end{document}
share|improve this answer
    
You are right; the opacity "leaks", so this is not the complete solution. –  Emre Feb 24 '12 at 23:58

I specified a pseudo transparent color through mixing it with white. You can easily brighten any color by choosing the amount of white it should be combined with.

\colorlet{LightSpringGreen}{White!70!SpringGreen}

The greater the number the brighter the color gets. There are much more options, as discussed in this question: Understanding xcolor color mixing model

share|improve this answer
1  
But still it's an opaque color. In other words if you put it on some other text, it will block it completely. You have to change the opacity not the color tone. –  percusse Sep 7 '12 at 20:58
    
@percusse I edited my answer to make it more clear. Thank you for th additional information. –  JJD Sep 7 '12 at 22:29

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.