# Tikz: use opacity for fill, yet leave draw (lines) untouched

When I use the tikz key opacity for a polygon in a tikzpicture, it applies to the drawn fill as well as to the draw lines.

I would like to have it this way that the lines remain untouched by the opacity key, so that they behave as if they had opacity=1.

(What I do now is redraw the polygon with fill=none, but that is a crippled solution to the problem).

-

You can specify the fill opacity separately form the draw opacity. In the first example below I used opacity and in the second I used fill opacity which will only affect the fill and not the draw.

## Note:

• As pointed out by Martin Scharrer: Specifying \opacity=<x> affects both the fill and draw so is equivalent to saying fill opacity=<X>, draw opacity=<X>.
• fill opacity applies not only to the fill, but also applies to text. To override this behavior, you can separately set the text opacity which applies only to the text labels.

## Code:

\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [ultra thick, draw=black, fill=yellow, opacity=0.2]
(0,0) -- (0,1) -- (1,1) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}
\draw [ultra thick, draw=black, fill=yellow, fill opacity=0.2]
(0,0) -- (0,1) -- (1,1) -- cycle;
\end{tikzpicture}
\end{document}

-
It should be noted that opacity=<X> is just a short-cut for fill opacity=<X>,draw opacity=<X>. Both are actual to different low-level settings in the output file (e.g. PDF). –  Martin Scharrer Dec 21 '11 at 18:52
@MartinScharrer: Good point. Have added a note incorporating your comment. –  Peter Grill Dec 21 '11 at 19:09
wow, sometimes things can be so easy... I thought I had already tried that. Great! –  romeovs Dec 21 '11 at 20:54