Matrices with shadows
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@[email protected] west) rectangle (\tikz@[email protected] 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}
Less elegant than marmot's solution but maybe also interesting:
\documentclass{article}
\usepackage{amsmath,blkarray}
\usepackage{tikz}
\usetikzlibrary{shadows, shapes, positioning, matrix}
\makeatletter % from https://tex.stackexchange.com/a/129322/121799
\tikzset{no shadows/.code=\let\tikz@preactions\pgfutil@empty}
\makeatother
\begin{document}
\begin{tikzpicture}[
every node/.style = {draw,
fill=white,
drop shadow,
anchor=center,
text height=2ex,
text depth=0.25ex},
]
\matrix (leftmatrix) [no shadows,
draw=none,
matrix of nodes,
nodes in empty cells,
row sep =-\pgflinewidth,
column sep = -\pgflinewidth,
minimum width=0.5cm,
minimum height=0.5cm,
]
{
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=0.25 cm of leftmatrix, draw=none, no shadows, font=\itshape] (users) {users};
\matrix (rightmatrix) [no shadows,
draw=none,
matrix of nodes,
nodes in empty cells,
row sep =-\pgflinewidth,
column sep = -\pgflinewidth,
minimum width=0.5cm,
minimum height=0.5cm,
right= 0.25cm of users]
{
1 & 1 & 1 & & 1 & 1 & & \\
0 & 1 & & & & 0 & 0 & 1 \\
0 & & & & & 0 & 0 & \\
1 & & 1 & 1 & & & & 1 \\
0 & 1 & & & 1 & 1 & 1 & \\
& 1 & & & & & & \\
};
\node[above= 0.1cm of leftmatrix, draw=none, no shadows, font=\itshape] (itemsleft) {items};
\node[above= 0.1cm of rightmatrix, draw=none, no shadows, font=\itshape] (itemsright) {items};
\node[below= 0.25cm of leftmatrix, draw=none, no shadows, font=\bfseries] (captionleft) {Explicit Rating};
\node[below= 0.25cm of rightmatrix, draw=none, no shadows, font=\bfseries] (captionright) {Implicit Rating};
\node[draw=none, no shadows] at (leftmatrix-1-1|-itemsleft) {$i_1$};
\node[draw=none, no shadows] at (leftmatrix-1-8|-itemsleft) {$i_8$};
\node[draw=none, no shadows] at (rightmatrix-1-1|-itemsleft) {$i_1$};
\node[draw=none, no shadows] at (rightmatrix-1-8|-itemsleft) {$i_8$};
\draw[dotted] (leftmatrix-1-2-|leftmatrix.east) -- (rightmatrix-1-2-|rightmatrix.west)
node[midway,fill=white,inner sep=0.5pt, draw=none, no shadows]{$u_1$};
\draw[dotted] (leftmatrix-6-2-|leftmatrix.east) -- (rightmatrix-6-2-|rightmatrix.west)
node[midway,fill=white,inner sep=0.5pt, draw=none, no shadows]{$u_6$};
\end{tikzpicture}
\end{document}
Or without no shadows
.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadows, shapes, positioning, matrix}
\begin{document}
\begin{tikzpicture}[
every node/.style = {draw,
fill=white,
anchor=center,
text height=2ex,
text depth=0.25ex},
]
\matrix (leftmatrix) [fill=white,drop shadow,inner sep=0pt,
draw=none,
matrix of nodes,
nodes in empty cells,
row sep =-\pgflinewidth,
column sep = -\pgflinewidth,
cells={minimum width=0.5cm,
minimum height=0.5cm}
]
{
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=0.25 cm of leftmatrix, draw=none, font=\itshape] (users) {users};
\matrix (rightmatrix) [fill=white,drop shadow,inner sep=0pt,
draw=none,
matrix of nodes,
nodes in empty cells,
row sep =-\pgflinewidth,
column sep = -\pgflinewidth,
cells={minimum width=0.5cm,
minimum height=0.5cm},
right= 0.25cm of users]
{
1 & 1 & 1 & & 1 & 1 & & \\
0 & 1 & & & & 0 & 0 & 1 \\
0 & & & & & 0 & 0 & \\
1 & & 1 & 1 & & & & 1 \\
0 & 1 & & & 1 & 1 & 1 & \\
& 1 & & & & & & \\
};
\node[above= 0.1cm of leftmatrix, draw=none, font=\itshape] (itemsleft) {items};
\node[above= 0.1cm of rightmatrix, draw=none, font=\itshape] (itemsright) {items};
\node[below= 0.25cm of leftmatrix, draw=none, font=\bfseries] (captionleft) {Explicit Rating};
\node[below= 0.25cm of rightmatrix, draw=none, font=\bfseries] (captionright) {Implicit Rating};
\node[draw=none] at (leftmatrix-1-1|-itemsleft) {$i_1$};
\node[draw=none] at (leftmatrix-1-8|-itemsleft) {$i_8$};
\node[draw=none] at (rightmatrix-1-1|-itemsleft) {$i_1$};
\node[draw=none] at (rightmatrix-1-8|-itemsleft) {$i_8$};
\draw[dotted] (leftmatrix-1-2-|leftmatrix.east) -- (rightmatrix-1-2-|rightmatrix.west)
node[midway,fill=white,inner sep=0.5pt, draw=none]{$u_1$};
\draw[dotted] (leftmatrix-6-2-|leftmatrix.east) -- (rightmatrix-6-2-|rightmatrix.west)
node[midway,fill=white,inner sep=0.5pt, draw=none]{$u_6$};
\end{tikzpicture}
\end{document}
If you are not inclined to learn Tikz, then just make a tabular. It doesn't take much code, the most sophisticated thing was the »shadow«.
\documentclass{article}
% \usepackage{amsmath}
\usepackage{array}
\usepackage{booktabs, colortbl}
\begin{document}
\renewcommand{\arraystretch}{1.3}\sffamily{}
\begin{tabular}{*{18}{|c} |c|}
\multicolumn{3}{l}{$i_1$} & \multicolumn{2}{c}{\raisebox{2ex}{items}} &
\multicolumn{3}{r}{$i_8$} & \multicolumn{3}{c}{} &
\multicolumn{3}{l}{$i_8$} & \multicolumn{2}{c}{\raisebox{2ex}{items}} &
\multicolumn{3}{r}{$i_8$}\\\cmidrule{1-8} \cmidrule{12-19}
5 & 1 & 3& &2 & 1 & & & \multicolumn{3}{c|}{\dots $u_1$ \dots} & 5 & 1 & 3& &2 & 1 & &\\\cmidrule{1-8} \cmidrule{12-19}
4 & 2 & & 3& & 4 & 3 & 1 & \multicolumn{3}{c|}{} & 4 & 2 & & 3& & 4 & 3 & 1 \\\cmidrule{1-8} \cmidrule{12-19}
1 & 3 & & & & 2 & 5 & & \multicolumn{3}{c|}{} & 1 & 3 & & & & 2 & 5 &\\\cmidrule{1-8} \cmidrule{12-19}
2 & 5 & 1& 2 & & & & 1 & \multicolumn{3}{c|}{users} & 2 & 5 & 1& 2 & & & & 1\\\cmidrule{1-8} \cmidrule{12-19}
0 & 4 & & & 5 &3 &1 & & \multicolumn{3}{c|}{} & 0 & 4 & & & 5 &3 &1 & \\\cmidrule{1-8} \cmidrule{12-19}
& 2 & & 4& &4 & 1& 2 & \multicolumn{3}{c|}{\dots $u_6$ \dots} & & 2 & & 4& &4 & 1& 2\\\cmidrule{1-8}
\cmidrule{12-19}\addlinespace[-4pt]
\arrayrulecolor[gray]{0.5}
\cmidrule[2pt](l{0.2ex}r{-.2ex}){1-8}
\cmidrule[2pt](l{0.2ex}r{-.2ex}){12-19}\addlinespace[2ex]
\multicolumn{8}{c}{\textbf{Explicit ratings}}& \multicolumn{3}{c}{} & \multicolumn{8}{c}{\textbf{Implicit ratings}}\\
\end{tabular}
\end{document}
Result:
EDIT
As suggested, with \clines
, instead of \cmidrules
. We need the latter for the shadow (as far as I know you can't trim \clines).
And I took the opportunity to streamline the layout, code of version 2:
\documentclass{article}
% \usepackage{amsmath}
\usepackage{array}
\usepackage{booktabs, colortbl, ragged2e}
\begin{document}
\renewcommand{\arraystretch}{1.8}\sffamily{}
\begin{tabular}{*{18}{|>{\Centering}p{1em}} |>{\Centering}p{1em}|}
\multicolumn{3}{l}{$i_1$} & \multicolumn{2}{c}{\raisebox{2ex}{items}} &
\multicolumn{3}{r}{$i_8$} & \multicolumn{3}{c}{} &
\multicolumn{3}{l}{$i_8$} & \multicolumn{2}{c}{\raisebox{2ex}{items}} &
\multicolumn{3}{r}{$i_8$}\\\cline{1-8} \cline{12-19}
5 & 1 & 3& &2 & 1 & & & \multicolumn{3}{c|}{\dots $u_1$ \dots} & 5 & 1 & 3& &2 & 1 & &\\\cline{1-8} \cline{12-19}
4 & 2 & & 3& & 4 & 3 & 1 & \multicolumn{3}{c|}{} & 4 & 2 & & 3& & 4 & 3 & 1 \\\cline{1-8} \cline{12-19}
1 & 3 & & & & 2 & 5 & & \multicolumn{3}{c|}{} & 1 & 3 & & & & 2 & 5 &\\\cline{1-8} \cline{12-19}
2 & 5 & 1& 2 & & & & 1 & \multicolumn{3}{c|}{users} & 2 & 5 & 1& 2 & & & & 1\\\cline{1-8} \cline{12-19}
0 & 4 & & & 5 &3 &1 & & \multicolumn{3}{c|}{} & 0 & 4 & & & 5 &3 &1 & \\\cline{1-8} \cline{12-19}
& 2 & & 4& &4 & 1& 2 & \multicolumn{3}{c|}{\dots $u_6$ \dots} & & 2 & & 4& &4 & 1& 2\\\cline{1-8}
\cline{12-19}\addlinespace[-1pt]
\arrayrulecolor[gray]{0.4}
\cmidrule[3pt](l{0.2ex}r{-.2ex}){1-8}
\cmidrule[3pt](l{0.2ex}r{-.2ex}){12-19}\addlinespace[1ex]
\multicolumn{8}{c}{\textbf{Explicit ratings}}& \multicolumn{3}{c}{} & \multicolumn{8}{c}{\textbf{Implicit ratings}}\\
\end{tabular}
\end{document}
And the picture: