TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to have transparency in a tikz picture while using the preview package and compiling with xelatex?

The following mwe compiles without warnings/errors under both xelatex and pdflatex but with xelatex there is no transparency. Everything is printed opaque. With pdflatex everything works as expected.






\begin{tikzpicture}[line width=1ex]
  \draw (0,0) -- (3,1);
  \filldraw [fill=red,draw opacity=0.5] (1,0) rectangle (2,1);

share|improve this question
Perhaps the problem is the same here : tex.stackexchange.com/questions/17080/… – Alain Matthes Jun 17 '11 at 13:35
There is an issue with XeLaTeX, preview package and TikZ shadings, most likely also with patterns and transparency. I as standalone class author, which uses preview, got contacted by a user two month ago because of it. I tracked it down to the above combination. The user then wrote an email to the preview author, but I didn't heard anything about it ever since. – Martin Scharrer Jun 17 '11 at 13:54
@Martin, I see. I'll send an email to the author too. I hope it is something easily fixed. – pmav99 Jun 17 '11 at 14:24
it also might be an issue of PGF/TikZ instead. Anyway it seems only to appear with XeLaTeX+preview+some feature of PGF/TikZ (shadings, patterns, transparency). It works without preview or with it under pdflatex. – Martin Scharrer Jun 17 '11 at 14:34
@Martin, Just removing the preview package outputs the expected result even with xelatex. So I don't think it is related with xelatex or/and pgf (of course I can be wrong). AFAIK Tikz's patterns problems are related with xelatex. – pmav99 Jun 17 '11 at 14:38
up vote 6 down vote accepted

You can avoid the issue by selecting the page size to be equal to the picture size. Therefore you don't need preview and it works fine with XeLaTeX. For this you need to save the picture in a box register. Because geometry only allows to select the page size in the preamble you need to move the picture there, which is OK as long it inside a savebox (like inside a lrbox environment).

I'm planning to build a feature like this into standalone as an alternative to preview.



\normalfont% required to select normal font already in the preamble
\begin{tikzpicture}[line width=1ex]
  \draw (0,0) -- (3,1);
  \filldraw [fill=red,draw opacity=0.5] (1,0) rectangle (2,1);



(The outer dark frame is the background of the PDF viewer)

The upcoming version 1.0 of standalone includes code similar to this and avoids the need of preview. It should work fine for XeLaTeX.

share|improve this answer
The fill color (red) is still opaque. I cannot see the black line inside the red rectangle. Herbert's answer can be used as a reference. – kiss my armpit Dec 12 '11 at 22:29
@CounterTerrorist: That's simple because draw opacity was used (by the OP, so I did the same). If you replace it by fill opacity or opacity (which does both) the filled rectangle will be transparent. – Martin Scharrer Dec 12 '11 at 22:36
I see.......... – kiss my armpit Dec 12 '11 at 22:40

if I use PSTricks and XeLaTeX together with preview, it works. The reason why I suppose a problem with TikZ and not preview

enter image description here

share|improve this answer
I sent an email to preview's author (no answer so far) and filled a bug report for tikz sourceforge.net/tracker/… – pmav99 Jun 19 '11 at 12:23
I cannot produce PSTricks transparency with XeLaTeX, see tex.stackexchange.com/q/38001/9467. – kiss my armpit Dec 12 '11 at 11:14

Your Answer


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.