发出蝙蝠信号
你能帮我画出这个矩阵以及箭头和注释吗?
梅威瑟:
\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}
答案1
我建议matrix
在 TikZ 中更好地访问锚点。使用 TikZ,您可以使用
('matrix name'-'row num'-'col num')
语法来访问单元格的锚点,从而方便绘图/填充。
代码
\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}