# 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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9345306754112244, "perplexity": 2340.526886683452}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-41/segments/1410657128304.55/warc/CC-MAIN-20140914011208-00255-ip-10-196-40-205.us-west-1.compute.internal.warc.gz"}