2

How can I add the same text that appear inside the area surrounded by the arrow above the phrase "Item-based", meaning, {$\mathrm{sim}(u_{a},u_{j})$} but inside the area surrounded by the arrow next to the text "User-based similarity measure"?

CODE

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
    \begin{tikzpicture}[font=\footnotesize,b/.style={text=blue,font=\bfseries}]
    \matrix(m)[matrix of nodes,
    nodes={minimum size=5ex,anchor=center,draw},
    row 1/.style={nodes={draw=none,fill=none}},
    column 5/.style={nodes={fill=gray!30}},
    column 6/.style={nodes={fill=gray!30}},
    row 4/.style={nodes={fill=orange!30}},
    column 1/.style={nodes={draw=none,fill=none}},
    row sep=-\pgflinewidth,
    column sep={-\pgflinewidth},
    nodes in empty cells,
    ]{
        & $i_{1}$& $i_{2}$ & $i_{3}$ & \dots &$ i_{k}$    & $ i_{a}$  & \dots &$ i_{n}$ \\ 
        $u_{1}$ & & 5 &   & 2 & 4    &    &  &  \\ 
        $u_{2}$ & & 5 & 4 &  & 5 &   & 4  &\\ 
        |[fill=none]|\dots & &   &   &  &   & 1 & 1 & 2   \\ 
        $u_{j}$ & 3 &  & |[b]| ? &  & |[b]| ? & 3 & &  0 \\ 
        $u_{a}$ & & |[b]| ? & 2 &  & 4 &  &|[b]| ? &  \\ 
        \dots& & |[b]| ? & 2 &  & 4 &  &|[b]| ? &  \\ 
        $u_{6}$ & & |[b]| ? & 2 &  & 4 &  &|[b]| ? &  \\
    };
    \draw[-latex](m-6-9.east)--+(1,0)node[above right]{User-based similarity measure}|-(m-5-9.east);
    \node[left]at(m-4-1.west){Active User};
    \draw[latex-] (m-1-6) -- ++ (-1,1) node[above left,align=left]
    {Item preference score is\\ predicted for active user};
    \draw[-latex]([xshift=-2pt]m-8-6.south east)--++(0,-1) -| 
    ([xshift=2pt]m-8-5.south west)
    node[pos=0.25,below]{Item-based}
    node[pos=0.25,above,font=\tiny]{$\mathrm{sim}(u_{a},u_{j})$};
    \end{tikzpicture}
\end{document}

enter image description here

2

Since the loop is built with the syntax |-, it is sufficient to use the specific placement of nodes on such paths. To know:

  • 0.5 is the right angle
  • .25 is half of the first segment.

For aesthetic reasons, I have divided the text into two lines.

\draw[-latex,align=center](m-6-9.east)--+(1.8,0)node[above right]{User-based\\ similarity measure}|-(m-5-9.east)node[pos=.25,left]{$\mathrm{sim}(u_{a},u_{j})$};

screenshot

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
    \begin{tikzpicture}[font=\footnotesize,b/.style={text=blue,font=\bfseries}]
    \matrix(m)[matrix of nodes,
    nodes={minimum size=5ex,anchor=center,draw},
    row 1/.style={nodes={draw=none,fill=none}},
    column 5/.style={nodes={fill=gray!30}},
    column 6/.style={nodes={fill=gray!30}},
    row 4/.style={nodes={fill=orange!30}},
    column 1/.style={nodes={draw=none,fill=none}},
    row sep=-\pgflinewidth,
    column sep={-\pgflinewidth},
    nodes in empty cells,
    ]{
        & $i_{1}$& $i_{2}$ & $i_{3}$ & \dots &$ i_{k}$    & $ i_{a}$  & \dots &$ i_{n}$ \\ 
        $u_{1}$ & & 5 &   & 2 & 4    &    &  &  \\ 
        $u_{2}$ & & 5 & 4 &  & 5 &   & 4  &\\ 
        |[fill=none]|\dots & &   &   &  &   & 1 & 1 & 2   \\ 
        $u_{j}$ & 3 &  & |[b]| ? &  & |[b]| ? & 3 & &  0 \\ 
        $u_{a}$ & & |[b]| ? & 2 &  & 4 &  &|[b]| ? &  \\ 
        \dots& & |[b]| ? & 2 &  & 4 &  &|[b]| ? &  \\ 
        $u_{6}$ & & |[b]| ? & 2 &  & 4 &  &|[b]| ? &  \\
    };
    \draw[-latex,align=center](m-6-9.east)--+(1.8,0)node[above right]{User-based\\ similarity measure}|-(m-5-9.east)node[pos=.25,left]{$\mathrm{sim}(u_{a},u_{j})$};
    \node[left]at(m-4-1.west){Active User};
    \draw[latex-] (m-1-6) -- ++ (-1,1) node[above left,align=left]
    {Item preference score is\\ predicted for active user};
    \draw[-latex]([xshift=-2pt]m-8-6.south east)--++(0,-1) -| 
    ([xshift=2pt]m-8-5.south west)
    node[pos=0.25,below]{Item-based}
    node[pos=0.25,above,font=\tiny]{$\mathrm{sim}(u_{a},u_{j})$};
    \end{tikzpicture}
\end{document}
3

This is more or less repetition from the answer that yielded your code. It is designed in such a way that, if you add more text, the arrow loop will adjust its size.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
    \begin{tikzpicture}[font=\footnotesize,b/.style={text=blue,font=\bfseries}]
    \matrix(m)[matrix of nodes,
    nodes={minimum size=5ex,anchor=center,draw},
    row 1/.style={nodes={draw=none,fill=none}},
    column 5/.style={nodes={fill=gray!30}},
    column 6/.style={nodes={fill=gray!30}},
    row 4/.style={nodes={fill=orange!30}},
    column 1/.style={nodes={draw=none,fill=none}},
    row sep=-\pgflinewidth,
    column sep={-\pgflinewidth},
    nodes in empty cells,
    ]{
        & $i_{1}$& $i_{2}$ & $i_{3}$ & \dots &$ i_{k}$    & $ i_{a}$  & \dots &$ i_{n}$ \\ 
        $u_{1}$ & & 5 &   & 2 & 4    &    &  &  \\ 
        $u_{2}$ & & 5 & 4 &  & 5 &   & 4  &\\ 
        |[fill=none]|\dots & &   &   &  &   & 1 & 1 & 2   \\ 
        $u_{j}$ & 3 &  & |[b]| ? &  & |[b]| ? & 3 & &  0 \\ 
        $u_{a}$ & & |[b]| ? & 2 &  & 4 &  &|[b]| ? &  \\ 
        \dots& & |[b]| ? & 2 &  & 4 &  &|[b]| ? &  \\ 
        $u_{6}$ & & |[b]| ? & 2 &  & 4 &  &|[b]| ? &  \\
    };
    \node[left]at(m-4-1.west){Active User};
    \path (m-6-9.south east) -- (m-5-9.north east) 
     node[midway,right,font=\tiny] (ub) {$\mathrm{sim}(u_{a},u_{j})$};
    \draw[-latex](m-6-9.east) --
    ([xshift=2pt]ub.east|-m-6-9.east) |-(m-5-9.east)
    node[pos=0.25,right,align=left]  {User-based si-\\milarity measure};
    ;
    \draw[latex-] (m-1-6.north) -- ++ (-1,1) node[above left,align=left]
    {Item preference score is\\ predicted for active user};
    \draw[-latex]([xshift=-2pt]m-8-6.south east)--++(0,-1) -| 
    ([xshift=2pt]m-8-5.south west)
    node[pos=0.25,below]{Item-based}
    node[pos=0.25,above,font=\tiny]{$\mathrm{sim}(u_{a},u_{j})$};
    \end{tikzpicture}
\end{document}

enter image description here

To see this automatic adjustment, try

\path (m-6-9.south east) -- (m-5-9.north east) 
 node[midway,right] (ub) {$\mathrm{sim}(u_{a},u_{j})$};

to get

enter image description here

There is no hardcoded distance.

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.