[Tex/LaTex] tikz picture: draw opacity vs fill opacity

graphicstikz-pgftransparency

\documentclass{article}
\usepackage{tikz}

\begin{document}
\pagenumbering{gobble}

\hskip-1.25in
\begin{tikzpicture}[thick,fill opacity=.4,draw opacity=1]
%\draw[step=1cm] (-9,-9) grid (9,9);
%\filldraw[fill=black,fill opacity=1] (0,0) circle (.5mm);
\draw[fill=yellow] (-9,-8) rectangle (9,8);
\draw[fill=orange,dashed] (-3,-5) rectangle (9,5);
\draw[fill=green,dotted] (-3,-4) rectangle (5,4);
\draw[fill=red] (-9,-6) rectangle (2,6);
\draw[fill=blue] (-6,-2) rectangle (0,2);
\end{tikzpicture}

\end{document}

leaves the borders of the superimposed rectangles with different thicknesses/opacities (as you can see below).

enter image description here

How can I set the thicknesses of each rectangle to show up through the more transparent fill? I thought this is what draw opacity=1 would accomplish.

Best Answer

draw opacity=1 does indeed draw opaque lines, but the appearance will be affected if you then place something in front (on top?) of that object. You can thus change the order in which you draw objects to emphasize their appearance.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[thick,fill opacity=.4,draw opacity=1]
\draw[fill=yellow] (-9,-8) rectangle (9,8);
\draw[fill=red] (-9,-6) rectangle (2,6);
\draw[fill=orange,dashed] (-3,-5) rectangle (9,5);
\draw[fill=green,dotted] (-3,-4) rectangle (5,4);
\draw[fill=blue] (-6,-2) rectangle (0,2);
\end{tikzpicture}
\end{document}

Another option is to draw the filled parts first and the borders last, to ensure the border lines are not obscured.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[thick,fill opacity=.4,draw opacity=1]
\fill[yellow] (-9,-8) rectangle (9,8);
\fill[red] (-9,-6) rectangle (2,6);
\fill[orange,] (-3,-5) rectangle (9,5);
\fill[green,dotted] (-3,-4) rectangle (5,4);
\fill[blue] (-6,-2) rectangle (0,2);
%
\draw (-9,-8) rectangle (9,8);
\draw (-9,-6) rectangle (2,6);
\draw[dashed] (-3,-5) rectangle (9,5);
\draw[dotted] (-3,-4) rectangle (5,4);
\draw (-6,-2) rectangle (0,2);
\end{tikzpicture}
\end{document}