4

Sending out the bat signal

Can you help me to draw this matrix along with the arrows and the comments?

enter image description here

MWE:

  \documentclass{beamer}
\usepackage{xcolor}
\usepackage{array}
\usepackage{hhline}
\usepackage{lmodern}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tabular}{cc}
 & \\
 &
 \begin{tabular}{c | c | c | c | c | c | c | c |  c |  }


\multicolumn{1}{c}{} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{2} 
& \multicolumn{1}{c}{3} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{5} 
& \multicolumn{1}{c}{6} & \multicolumn{1}{c}{7} & \multicolumn{1}{c}{8} \\ \hhline{~*8{|-}|}
$u_{1}$ & & 5 &   & 2 & 4    &    &  &  \\ \hhline{~*8{|-}|} 
$u_{2}$ & 4 &  & 3 & 1 &  &   & 3  &   \\ \hhline{~*8{|-}|} 
$u_{3}$ & & 5 & 4 &  & 5 &   & 4  &\\ \hhline{~*8{|-}|}
$u_{4}$ & &   &   &  &   & 1 & 1 & 2   \\ \hhline{~*8{|-}|}
$u_{5}$ & 3 &  & \color{blue}\textbf{?} &  & \color{blue}\textbf{?} & 3 & &  0 \\ \hhline{~*8{|-}|}
$u_{6}$ & & \color{blue}\textbf{?} & 2 &  & 4 &  &\color{blue}\textbf{?} &  \\ \hhline{~*8{|-}|}
\end{tabular}
\end{tabular}
\end{frame}
\end{document}

enter image description here

6

I would suggest matrix in TikZ for better access to anchors. With TikZ, you can use the

('matrix name'-'row num'-'col num')

syntax to access anchors of the cells and thus facilitate drawing/filling.

Code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,backgrounds}
\begin{document}
  \centering 
  \begin{tikzpicture}[font=\footnotesize]
    \matrix(m)[matrix of nodes,
      nodes={minimum size=5ex,anchor=center,draw},column 1/.style={nodes={draw=none}},row 1/.style={nodes={draw=none}},
      row sep=-\pgflinewidth,
      column sep={-\pgflinewidth},
      nodes in empty cells,
    ]{
              & 1 & 2 & 3 & 4 & 5    &  6  & 7 & 8 \\ 
      $u_{1}$ & & 5 &   & 2 & 4    &    &  &  \\ 
      $u_{3}$ & & 5 & 4 &  & 5 &   & 4  &\\ 
      $u_{4}$ & &   &   &  &   & 1 & 1 & 2   \\ 
      $u_{5}$ & 3 &  & \color{blue}\textbf{?} &  & \color{blue}\textbf{?} & 3 & &  0 \\ 
      $u_{6}$ & & \color{blue}\textbf{?} & 2 &  & 4 &  &\color{blue}\textbf{?} &  \\ 
    };
    \begin{scope}[on background layer]
      \fill[orange!30](m-2-5.north west)rectangle(m-6-5.south east);
      \fill[gray!30](m-2-6.north west)rectangle(m-6-6.south east);
      \fill[orange!30](m-4-2.north west)rectangle(m-4-9.south east);
    \end{scope}
    \draw[-latex](m-4-9.east)--+(1,0)node[above right]{User-based similarity measure}|-(m-3-9.east);
    \node[left]at(m-4-1.west){Active User};
  \end{tikzpicture}
\end{document}

Output

enter image description here

  • 1
    Thank you very much! Looks great! Is there any way to label the columns as well? – NaveganTeX Jul 8 at 17:15
  • @NaveganTeX: Do you mean by adding a first row? – Herr K. Jul 8 at 17:16
  • Just like u_{1} but in the case of colums it would be i_{1} I don’t know if by adding an extra row you can add the label, maybe you can – NaveganTeX Jul 8 at 17:19
  • 1
    @NaveganTeX: Yes, simply adding a first row would do. See my update. – Herr K. Jul 8 at 17:24
  • Awesome! Thank you. I’ll get back to you if I cannot draw the other similarity ;) – NaveganTeX Jul 8 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.