我能够绘制矩阵,但是有一个技巧。
蓝色阴影只是一个矩形,而不是阴影。
在我的示例中,我有一个阴影。我想知道如何替换原始阴影。
手机上开启夜间模式的原图,可以更清楚地了解我的意思:
我的+代码:
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,shadows.blur,positioning,decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[,decoration={brace,mirror,raise=0.1em}]
\matrix (A) [matrix of math nodes, nodes in empty cells,inner sep=0pt,
nodes={draw, minimum width=12mm, minimum height=12mm, outer sep=0pt,
anchor=center},row sep=-\pgflinewidth, column sep=-\pgflinewidth,
row 1/.style = {nodes={minimum height=8mm}},
row 3/.style = {nodes={minimum height=8mm,fill=lightgray}},
row 5/.style = {nodes={minimum height=8mm}},
column 1/.style = {nodes={minimum width=8mm}},
column 3/.style = {nodes={minimum width=8mm,fill=lightgray}},
column 5/.style = {nodes={minimum width=8mm}},
fill=white,blur shadow]
{ r_{11} & & r_{1g} & & r_{1n}\\
& & & & \\
r_{i1} & & |[fill=black,text=white]| r_{ig} & & r_{in}\\
& & & & \\
r_{m1} & & r_{mg} & & r_{mn}\\
};
\foreach \X/\Y in {1/1,3/g,5/n}
{\node[above=0.2em of A-1-\X] (T-\X) {$\Y$};}
\foreach \X/\Y in {1/1,3/i,5/m}
{\node[left=0.2em of A-\X-1] (L-\X) {$\Y$};}
\draw[decorate] (T-3.south-|A.east) -- (T-3.north-|A.east)
node[midway,right=0.1em] {$G$};
\draw[decorate] (A-3-5.south-|A.east) -- (A-3-5.north-|A.east)
node[midway,right=0.1em] {$R_i$};
\draw[decorate] (L-5.west|-A.south) --
(L-5.east|-A.south) node[midway,below=0.1em] {$I$};
\draw[decorate] (A-5-3.west|-A.south) --
(A-5-3.east|-A.south) node[midway,below=0.1em] {$R_g$};
\node[above=0.2em of T-3] {items};
\node[left=0.2em of L-3] {users};
\end{tikzpicture}
\end{document}
答案1
怎么样
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,shadows.blur,positioning,decorations.pathreplacing}
\makeatletter
\tikzset{render blur shadow/.code={\pgfbs@savebb%
\pgfsyssoftpath@getcurrentpath{\pgfbs@input@path}%
\pgfbs@compute@shadow@bbox%
\pgfbs@process@rounding{\pgfbs@input@path}{\pgfbs@fadepath}%
\pgfbs@apply@canvas@transform%
\colorlet{pstb@shadow@color}{white!\pgfbs@opacity!#1}%
\pgfdeclarefading{shadowfading}{\pgfbs@paint@fading}%
\pgfsetfillcolor{#1}%
\pgfsetfading{shadowfading}{\pgftransformshift{\pgfpoint{\pgfbs@midx}{\pgfbs@midy}}}%
\pgfbs@usebbox{fill}%
\pgfbs@restorebb%
},render blur shadow/.default=shadowcolor}
\colorlet{shadowcolor}{black}
\makeatother
\begin{document}
\begin{tikzpicture}[,decoration={brace,mirror,raise=0.3em}]
\colorlet{shadowcolor}{blue}
\matrix (A) [matrix of math nodes, nodes in empty cells,inner sep=0pt,
nodes={draw, minimum width=12mm, minimum height=12mm, outer sep=0pt,
anchor=center},row sep=-\pgflinewidth, column sep=-\pgflinewidth,
row 1/.style = {nodes={minimum height=8mm}},
row 3/.style = {nodes={minimum height=8mm,fill=lightgray}},
row 5/.style = {nodes={minimum height=8mm}},
column 1/.style = {nodes={minimum width=8mm}},
column 3/.style = {nodes={minimum width=8mm,fill=lightgray}},
column 5/.style = {nodes={minimum width=8mm}},
fill=white,blur shadow={shadow blur steps=10,shadow xshift=0em,shadow
yshift=0em,shadow blur radius=1.5ex,shadow scale=1.1}]
{ r_{11} & & r_{1g} & & r_{1n}\\
& & & & \\
r_{i1} & & |[fill=black,text=white]| r_{ig} & & r_{in}\\
& & & & \\
r_{m1} & & r_{mg} & & r_{mn}\\
};
\foreach \X/\Y in {1/1,3/g,5/n}
{\node[above=0.2em of A-1-\X] (T-\X) {$\Y$};}
\foreach \X/\Y in {1/1,3/i,5/m}
{\node[left=0.2em of A-\X-1] (L-\X) {$\Y$};}
\draw[decorate] (T-3.south-|A.east) -- (T-3.north-|A.east)
node[midway,right=0.3em] {$G$};
\draw[decorate] (A-3-5.south-|A.east) -- (A-3-5.north-|A.east)
node[midway,right=0.3em] {$R_i$};
\draw[decorate] (L-5.west|-A.south) --
(L-5.east|-A.south) node[midway,below=0.3em] {$I$};
\draw[decorate] (A-5-3.west|-A.south) --
(A-5-3.east|-A.south) node[midway,below=0.3em] {$R_g$};
\node[above=0.2em of T-3] {items};
\node[left=0.2em of L-3] {users};
\end{tikzpicture}
\end{document}
如果你使用
blur shadow={shadow blur steps=10,shadow xshift=0em,shadow yshift=0em,shadow blur radius=1.5ex,shadow scale=1.1,shadow opacity=0.2}
相反,你得到
您可以调整参数直到找到完美匹配,我不知道您到底想要实现什么。