箭头指向不正确

箭头指向不正确

你能帮我把箭头弄好吗?还有,我该如何把它放在sim(u_{a},u_{j})箭头所围的区域内?

在此处输入图片描述

\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,
    ]{
        & $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  &\\ 
        \dots & &   &   &  &   & 1 & 1 & 2   \\ 
        $u_{j}$ & 3 &  & \color{blue}\textbf{?} &  & \color{blue}\textbf{?} & 3 & &  0 \\ 
        $u_{a}$ & & \color{blue}\textbf{?} & 2 &  & 4 &  &\color{blue}\textbf{?} &  \\ 
        \dots& & \color{blue}\textbf{?} & 2 &  & 4 &  &\color{blue}\textbf{?} &  \\ 
        $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-5.north west)rectangle(m-8-6.south east);
    \fill[orange!30](m-4-2.north west)rectangle(m-4-9.south east);
    \end{scope}
    \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-2-5.north west)--+(1,0)node[below right]{Item-based }|-(m-8-6.south east);


    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

这样就修复了箭头。

\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,
    ]{
        & $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  &\\ 
        \dots & &   &   &  &   & 1 & 1 & 2   \\ 
        $u_{j}$ & 3 &  & \color{blue}\textbf{?} &  & \color{blue}\textbf{?} & 3 & &  0 \\ 
        $u_{a}$ & & \color{blue}\textbf{?} & 2 &  & 4 &  &\color{blue}\textbf{?} &  \\ 
        \dots& & \color{blue}\textbf{?} & 2 &  & 4 &  &\color{blue}\textbf{?} &  \\ 
        $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-5.north west)rectangle(m-8-6.south east);
    \fill[orange!30](m-4-2.north west)rectangle(m-4-9.south east);
    \end{scope}
    \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}

在此处输入图片描述

这是获得相同结果的另一种方法(不一定更好)。它不是在背景层上填充(这完全没问题),而是通过样式填充单元格。

\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}

相关内容