[Tex/LaTex] Matrices with shadows

matricestikz-pgf

I'm trying to draw the shadows and also the dots between the two matrices:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}


    \centering
        \begin{tabular}{|c|c|c|c|c|c|c|c|}
        \hline
        5   & 1 &  3&  &2  & 1 & &  \\ \hline
        4   & 2 &  &  3&  & 4 & 3 & 1 \\ \hline
        1   & 3 &  &  &  & 2 & 5 & \\ \hline
        2   & 5 &  1& 2 &  & & & 1 \\ \hline
        0   & 4 &  &  & 5 &3  &1 & \\ \hline
        & 2 &  &  4&  &4 & 1& 2 \\ \hline

        \hline
    \end{tabular}
    \begin{tabular}{|c|c|c|c|c|c|c|c|}
        \hline
     1  & 1 &  1&  &1  & 1 & &  \\ \hline
     0  & 1 &  &  &  & 0 & 0 & 1 \\ \hline
    0   &  &  &  &  & 0 & 0 & \\ \hline
    1   &  &  1& 1 &  & & & 1 \\ \hline
    0   & 1 &  &  & 1 &1  &1 & \\ \hline
        & 1 &  &  &  & & &  \\ \hline

        \hline
    \end{tabular}



\end{document}

enter image description here

Best Answer

Shadows can be cast (a) by groundhogs, (b) with shadows, and (c) with shadows.blur. I use shadows.blur here because you seem not to be asking for a duck-shaped shadow. The styles for the dividing lines and the frame are from here. I made the cells quadratic in the update.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,calc,positioning,fit,backgrounds,shadows.blur}
\makeatletter
\long\def\ifnodedefined#1#2#3{%
    \@ifundefined{pgf@sh@ns@#1}{#3}{#2}%
}
\tikzset{matrix vlines/.style={execute at end matrix={
\foreach \XX in {1,...,\the\pgf@matrix@numberofcolumns}
{\xdef\FitList{}
\foreach \YY in {1,...,\the\pgfmatrixcurrentrow}
{\ifnodedefined{\tikzmatrixname-\YY-\XX}{\xdef\FitList{\FitList (\tikzmatrixname-\YY-\XX)}}{}
}
\node[fit=\FitList,draw=none,fill=none,inner sep=0pt,draw=none] (\tikzmatrixname-col-\XX) {};
}
\foreach \XX in {2,...,\the\pgf@matrix@numberofcolumns}
{\draw[#1] ($(\tikzmatrixname-col-\XX.west)!0.5!(\tikzmatrixname-col-\the\numexpr\XX-1\relax.east)$)
coordinate (aux) (aux|-\tikzmatrixname.north)
 --  (aux|-\tikzmatrixname.south);
}
}},matrix hlines/.style={execute at end matrix={
\foreach \YY in {1,...,\the\pgfmatrixcurrentrow}
{\xdef\FitList{}
\foreach \XX in {1,...,\the\pgf@matrix@numberofcolumns}
{\ifnodedefined{\tikzmatrixname-\YY-\XX}{\xdef\FitList{\FitList (\tikzmatrixname-\YY-\XX)}}{}
}
\node[fit=\FitList,draw=none,fill=none,inner sep=0pt,draw=none] (\tikzmatrixname-row-\YY) {};
}
\foreach \XX in {2,...,\the\pgfmatrixcurrentrow}
{\draw[#1] ($(\tikzmatrixname-row-\XX)!0.5!(\tikzmatrixname-row-\the\numexpr\XX-1\relax)$)
coordinate (aux) (aux-|\tikzmatrixname.west)
 --  (aux-|\tikzmatrixname.east);
}
}},
matrix dividers/.style={matrix vlines=#1,matrix hlines=#1},
matrix frame/.style={execute at end matrix={
\draw[#1] (\tikz@fig@name.south west) rectangle (\tikz@fig@name.north east);
}}}
\makeatother
\begin{document}
\begin{tikzpicture}[font=\sffamily\itshape,node distance=0.3em,
s-matrix/.style={matrix dividers,matrix frame,matrix of math nodes,
nodes in empty cells,fill=white,blur shadow,inner sep=0pt,
cells={text height=0.8em,text depth=0.2em,minimum width=1.8em,minimum height=1.8em}}]
\matrix[s-matrix] (mat1) {
        5   & 1 &  3&  &2  & 1 & &  \\ 
        4   & 2 &  &  3&  & 4 & 3 & 1 \\ 
        1   & 3 &  &  &  & 2 & 5 & \\ 
        2   & 5 &  1& 2 &  & & & 1 \\ 
        0   & 4 &  &  & 5 &3  &1 & \\ 
        & 2 &  &  4&  &4 & 1& 2 \\ 
};
\node[right=of mat1] (users) {users};
\matrix[s-matrix,right=of users] (mat2) {
     1  & 1 &  1&  &1  & 1 & &  \\ 
     0  & 1 &  &  &  & 0 & 0 & 1 \\ 
    0   &  &  &  &  & 0 & 0 & \\ 
    1   &  &  1& 1 &  & & & 1 \\ 
    0   & 1 &  &  & 1 &1  &1 & \\ 
        & 1 &  &  &  & & &  \\ 
};
\foreach \X in {1,2}
{\node[above=of mat\X] (items-\X) {items};
\node at (mat\X-1-1|-items-\X) {i$_1$};
\node at (mat\X-1-8|-items-\X) {i$_8$};}
\foreach \X in {1,6}
{\draw[dotted] (mat1-\X-2-|mat1.east) -- (mat2-\X-2-|mat2.west)
 node[midway,fill=white,inner sep=0.5pt]{u$_\X$};}
\node[below=1em of mat1,font=\sffamily\bfseries]  {Explicit ratings};
\node[below=1em of mat2,font=\sffamily\bfseries]  {Implicit ratings};
\end{tikzpicture}
\end{document}

enter image description here