135

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).

0

1 Answer 1

195

You can specify the fill opacity separately from 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.

enter image description here

Note:

  • As pointed out by Martin Scharrer: Specifying \opacity=<x> affects the fill, draw and text so is equivalent to saying fill opacity=<X>, draw opacity=<X>, text 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. So, apply text opacity=1 to ensure that opacity is not applied to the text.

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}
7
  • 25
    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). Dec 21, 2011 at 18:52
  • @MartinScharrer: Good point. Have added a note incorporating your comment. Dec 21, 2011 at 19:09
  • wow, sometimes things can be so easy... I thought I had already tried that. Great!
    – romeovs
    Dec 21, 2011 at 20:54
  • 9
    Note that when there is text inside the node, it will also fade. Use text opacity=1.
    – oarfish
    Sep 1, 2015 at 8:57
  • @oarfish: That was the intent of the second bullet point, but have expanded to make it more explicit. Sep 3, 2015 at 17:32

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.