\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}
使叠加矩形的边框具有不同的厚度/不透明度(如下所示)。
我如何设置每个矩形的厚度以通过更透明的填充显示出来?我认为这就是 draw opacity=1 可以实现的。
答案1
draw opacity=1
确实会绘制不透明线,但如果您在该对象前面(顶部?)放置某些东西,外观将受到影响。因此,您可以更改绘制对象的顺序以强调其外观。
\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}
另一种选择是先画填充部分,最后画边框,以确保边框线不被遮挡。
\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}