2

Sending out the cat 😺 signal I need to get what's on the screenshot. I've tried by playing with scale but I've failed. Could you give me a hand?

enter image description here

Mine looks horrible :(

    \documentclass{standalone}
\usepackage{tikz}
\usepackage{adjustbox}
\usepackage{array}
\usepackage{contour}
\contourlength{1pt}
\usetikzlibrary{tikzmark}
\begin{document}
    \sffamily
        \centering\renewcommand{\arraystretch}{2}
        \begin{adjustbox}{max width=\textwidth}
        \begin{tabular}{rc}
            & \hspace{15mm} Movies \\
        Users &\centering%\renewcommand{\arraystretch}{3}
            \begin{tabular}{ l |>{\centering}p{2cm}| r }
                &      A    &   B  \\ \hline
                1 & $\tikzmarknode{a11}{r_{1A}}$~ & ~$\tikzmarknode{a12}{r_{1B}}$ \\ \hline
                2 & $\tikzmarknode{a21}{r_{2A}}$~  & ~$\tikzmarknode{a22}{r_{BA}}$ \\ \hline  
            \end{tabular}  
        \end{tabular}
    \end{adjustbox}
        \begin{tikzpicture}[overlay,remember picture]
        \draw[stealth-stealth,black] (a11.north east) --  (a12.north west)
        node[midway,above,scale=0.7,black] (dAB)    {\contour{white}{$d_{AB}$}};
        \draw[-stealth,black] (a21.south east) -- (a22.south   west);
        \draw[-stealth,black,densely dotted] (dAB.south) to[out=0,in=80] (dAB.south|-a22);
        \draw[stealth-stealth] (a11.east) -- (a21.east)
        node[pos=0.5,right,scale=0.7,black] (d12) {\contour{white}{$d_{12}$}};
        \draw[-stealth,densely dotted] (d12.north) to[out=0,in=180] ([yshift=-1ex]a12.west);
        \end{tikzpicture}

\end{document}

enter image description here

4

I'd use a matrix of nodes. You can make it larger or smaller by increasing or deceasing \mylength.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{contour}
\contourlength{1pt}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[font=\sffamily]
 \def\mylength{4em}
 \matrix[matrix of nodes,column sep=3em,row sep=\mylength,inner sep=0.5*\mylength,
 cells={nodes={inner sep=2pt}}](mat){
    & A & B \\
  1 & $r_{1A}$ & $r_{1B}$\\
  2 & $r_{2A}$ & $r_{2B}$\\};
  \foreach \X in {1,2}{
  \path (mat-\X-3.south) -- (mat-\the\numexpr\X+1\relax-3.north) 
    coordinate[midway] (auxH-\X)
    (mat-2-\X.east) -- (mat-2-\the\numexpr\X+1\relax.west) 
    coordinate[midway] (auxV-\X);
  \draw (mat.west|-auxH-\X) -- (mat.east|-auxH-\X);
  \draw (mat.north-|auxV-\X) -- (mat.south-|auxV-\X);}
  \draw (mat.south west) -- (mat.south east);
  \draw[stealth-stealth] (mat-2-2.north east) --  (mat-2-3.north west)
   node[midway,above,scale=0.7] (dAB)    {\contour{white}{$d_{AB}$}};
  \draw[-stealth] (mat-3-2.south east) -- (mat-3-3.south   west);
  \draw[-stealth] (mat-2-3) -- (mat-3-3) coordinate[pos=1/3](aux);
  \draw[-stealth,densely dotted] (dAB.south) to[out=0,in=80] ++ (1em,-1em)
  to[out=-100,in=90]
  ([xshift=3pt]dAB.south|-mat-3-3);
  \draw[stealth-stealth] (mat-2-2.south east) -- (mat-3-2.east)
    node[pos=0.5,right,scale=0.7] (d12) {\contour{white}{$d_{12}$}};
  \draw[-stealth,densely dotted] (d12.north) to[out=10,in=170] ++ (2em,1em)
  to[out=-10,in=180]   (aux);
  \node[above] at (auxV-2|-mat.north){Movies};
  \node[left] at (auxH-2-|mat.west){Users};
\end{tikzpicture}
\end{document}

enter image description here

  • It gets complicated when you want to add the movies and users labels – NaveganTeX Oct 14 at 17:49
  • 1
    @NaveganTeX Not at all, I just missed to add them. It is very easy. – Schrödinger's cat Oct 14 at 17:57
4

Add dashed for dashed lines:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{array}
\usepackage{contour}
\contourlength{1pt}
\usetikzlibrary{tikzmark}
\begin{document}
    \sffamily
        \centering\renewcommand{\arraystretch}{2}
        \begin{tabular}{rc}
            & Movies \\
            Users &\centering%\renewcommand{\arraystretch}{3}
            \begin{tabular}{ l |>{\centering}p{1cm}| r }
                &      A    &   B  \\ \hline
                1 & $\tikzmarknode{a11}{r_{1A}}$~ & ~$\tikzmarknode{a12}{r_{1B}}$ \\ \hline
                2 & $\tikzmarknode{a21}{r_{2A}}$~  & ~$\tikzmarknode{a22}{r_{BA}}$ \\ \hline  
            \end{tabular}  
        \end{tabular}

        \begin{tikzpicture}[overlay,remember picture]
        \draw[stealth-stealth,blue] (a11.north east) --  (a12.north west)
        node[midway,above,scale=0.7,black] (dAB)    {\contour{white}{$d_{AB}$}};
        \draw[-stealth,blue] (a21.south east) -- (a22.south   west);
        \draw[-stealth,blue,dashed] (dAB.south) to[out=0,in=80] (dAB.south|-a22);
        \draw[stealth-stealth] (a11.east) -- (a21.east)
        node[pos=0.5,right,scale=0.7,black] (d12) {\contour{white}{$d_{12}$}};
        \draw[-stealth,dashed] (d12.north) to[out=0,in=180] ([yshift=-1ex]a12.west);
        \end{tikzpicture}

\end{document}

enter image description here

Or densely dotted:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{array}
\usepackage{contour}
\contourlength{1pt}
\usetikzlibrary{tikzmark}
\begin{document}
    \sffamily
        \centering\renewcommand{\arraystretch}{2}
        \begin{tabular}{rc}
            & Movies \\
            Users &\centering%\renewcommand{\arraystretch}{3}
            \begin{tabular}{ l |>{\centering}p{1cm}| r }
                &      A    &   B  \\ \hline
                1 & $\tikzmarknode{a11}{r_{1A}}$~ & ~$\tikzmarknode{a12}{r_{1B}}$ \\ \hline
                2 & $\tikzmarknode{a21}{r_{2A}}$~  & ~$\tikzmarknode{a22}{r_{BA}}$ \\ \hline  
            \end{tabular}  
        \end{tabular}

        \begin{tikzpicture}[overlay,remember picture]
        \draw[stealth-stealth,blue] (a11.north east) --  (a12.north west)
        node[midway,above,scale=0.7,black] (dAB)    {\contour{white}{$d_{AB}$}};
        \draw[-stealth,blue] (a21.south east) -- (a22.south   west);
        \draw[-stealth,blue,densely dotted] (dAB.south) to[out=0,in=80] (dAB.south|-a22);
        \draw[stealth-stealth] (a11.east) -- (a21.east)
        node[pos=0.5,right,scale=0.7,black] (d12) {\contour{white}{$d_{12}$}};
        \draw[-stealth,densely dotted] (d12.north) to[out=0,in=180] ([yshift=-1ex]a12.west);
        \end{tikzpicture}

\end{document}

enter image description here

  • Thank you very much, Maeve! It looks fantastic! – NaveganTeX Oct 14 at 15:06

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.