如何更改此 tikz 矩形的背景颜色?

如何更改此 tikz 矩形的背景颜色?

考虑以下 MWE:

\documentclass[tikz,pstricks,dvipsnames,border={1pt 1pt 1pt 1pt}]{standalone}

% PACKAGES LOADING

\usepackage{tikz} % To plot almost everything.

% TIKZ LIBRARIES & SETTINGS

\usetikzlibrary{fit, calc, matrix, positioning, arrows.meta, intersections, through, backgrounds, patterns, decorations.markings}

\begin{document}

% FIGURE 1

\begin{tikzpicture}[scale=.3,rounded corners=0.25pt]
\begin{scope}[line width=1.5pt]
\filldraw[color=black,opacity=0.05](6,5) rectangle (26,20);
\draw[black] (6,2) rectangle (30,20) (30,20) node[black,below left,scale=1] {$V_c$};
\filldraw[pattern=crosshatch,pattern color=black,opacity=0.20] (6,5) rectangle (26,20);
\filldraw[color=white, fill=black!0.2,opacity=1.0](8.5,3) rectangle +(19.5,9) (7,6);
\draw[black] (8.5,3) rectangle +(19.5,9) (28,12) node[black,below left,scale=1] {$V_f$};
\filldraw[color=black,opacity=0.05] (8.5,3) rectangle +(19.5,9) (28,12);
\draw[black] (4,4) rectangle (31,24) (31,24) node[black,below left,scale=1] {$V_n$}; 
\filldraw[color=black,opacity=0.05] (4,4) rectangle (31,24) (31,24); 
\draw[black] (2,5) rectangle (26,23) (2,23) node[black,below right,scale=1] {$V_m$};
\filldraw[color=black,opacity=0.05] (2,5) rectangle (26,23) (2,23);
\filldraw[color=white, fill=black!0.2, opacity=1.0](8.5,13) rectangle +(15,6) (7,13);
\draw[black] (8.5,13) rectangle +(15,6) (7,13) node[black,midway,scale=1] {$V_\kappa$};
\filldraw[color=black,opacity=0.05] (8.5,13) rectangle +(15,6) (7,13);
\draw[black] (9.5,6) rectangle +(15.5,5) (9.5,6) node[black,above right,scale=1] {$V_o$}; 
\filldraw[color=black,opacity=0.05] (9.5,6) rectangle +(15.5,5) (9.5,6); 
\fill[black] (21.0,8.5) circle(.25) +(0,0) node[black,right,scale=1] {$\nu_u$};
\filldraw[color=black,opacity=0.05] (21.0,8.5) circle(.25) +(0,0);
\draw[black] (19.0,10.0) rectangle (13,7.0) (16.0,9) node[midway,black,scale=1] {$V_d$};
\filldraw[color=black,opacity=0.05] (19.0,10.0) rectangle (13,7.0);
\draw (6,5) node[black, above right, scale=1] {$V_p$};
\end{scope}
\end{tikzpicture}

% FIGURE 2

\begin{tikzpicture}[scale=.3,rounded corners=0.25pt]
\begin{scope}[line width=1.5pt]
\filldraw[color=black,opacity=0.05](6,5) rectangle (26,20);
\draw[black] (6,2) rectangle (30,20) (30,20) node[black,below left,scale=1] {$V_c$};
\filldraw[pattern=crosshatch,pattern color=black,opacity=0.20] (6,5) rectangle (26,20);
\filldraw[color=white, fill=black!0.2,opacity=1.0](8.5,3) rectangle +(19.5,9) (7,6);
\draw[black] (8.5,3) rectangle +(19.5,9) (28,12) node[black,below left,scale=1] {$V_f$};
\filldraw[color=black,opacity=0.05] (8.5,3) rectangle +(19.5,9) (28,12);
\draw[black] (4,4) rectangle (31,24) (31,24) node[black,below left,scale=1] {$V_n$}; 
\filldraw[color=black,opacity=0.05] (4,4) rectangle (31,24) (31,24); 
\draw[black] (2,5) rectangle (26,23) (2,23) node[black,below right,scale=1] {$V_m$};
\filldraw[color=black,opacity=0.05] (2,5) rectangle (26,23) (2,23);
\filldraw[color=white, fill=black, opacity=1.0](8.5,13) rectangle +(15,6) (7,13);
\draw[black] (8.5,13) rectangle +(15,6) (7,13) node[black,midway,scale=1] {$V_\kappa$};
\filldraw[color=black,opacity=0.05] (8.5,13) rectangle +(15,6) (7,13);
\draw[black] (9.5,6) rectangle +(15.5,5) (9.5,6) node[black,above right,scale=1] {$V_o$}; 
\filldraw[color=black,opacity=0.05] (9.5,6) rectangle +(15.5,5) (9.5,6); 
\fill[black] (21.0,8.5) circle(.25) +(0,0) node[black,right,scale=1] {$\nu_u$};
\filldraw[color=black,opacity=0.05] (21.0,8.5) circle(.25) +(0,0);
\draw[black] (19.0,10.0) rectangle (13,7.0) (16.0,9) node[midway,black,scale=1] {$V_d$};
\filldraw[color=black,opacity=0.05] (19.0,10.0) rectangle (13,7.0);
\draw (6,5) node[black, above right, scale=1] {$V_p$};
\end{scope}
\end{tikzpicture}

\end{document}

这是输出:

在此处输入图片描述

我遇到的问题如下。图 1 中包含 $V_\kappa$ 的矩形的颜色应为\black!0.2。但是,当我使用 指定时\filldraw[color=white, fill=black!0.2, opacity=1.0](8.5,13) rectangle +(15,6) (7,13);,该三角形的背景为白色。但是,如果我改用 ,则\filldraw[color=white, fill=black, opacity=1.0](8.5,13) rectangle +(15,6) (7,13);$V_k$ 矩形的背景为黑色(代码应如此指定;参见图 2)。我怎样才能使 $V_\kappa$ 矩形的颜色为black!0.2?显然,我只能给它“全”颜色,我真的不知道为什么。

相关内容