5
\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.

  • (I don’t understand your question.) What is your problem? What did you expect to see? Can you simplify your example to two or three paths? The draw opacity key simply sets the opacity of the stroked path. The fill opacity sets the opacity of filled path. A value of 0 indicates invisibility (full see-through), a value of 1 means that nothing shines through. – Qrrbrbirlbel Nov 6 '13 at 19:36
6

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}
  • Not a very elegant solution though. Maybe someone else knows a better way. – erik Nov 6 '13 at 20:52
  • Worked just fine for me and was easy to implement. Thanks. – JohnD Nov 6 '13 at 23:03
  • @erik the new TikZ has some "blend" capabilities that probably would help – Sergio Parreiras Jun 4 '14 at 17:59
  • @SergioParreiras Thanks for pointing that out. I didn't notice Blend Modes have been added (although it's easy to overlook when the documentation exceeds 1100 pages). – erik Jun 8 '14 at 22:06

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.