有人能帮帮我吗?我知道如何创建表格,但不知道如何添加“用户”和“电影”标签。
这是我迄今为止尝试过的:
\begin{table}[H]
\centering
\text{ \textbf{Movies}}
\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{|-}|}
1 & & 5 & & 2 & 4 & & & \\ \hhline{~*8{|-}|}
2 & 4 & & 3 & 1 & & & 3 & \\ \hhline{~*8{|-}|}
3 & & 5 & 4 & & 5 & & 4 &\\ \hhline{~*8{|-}|}
4 & & & & & & 1 & 1 & 2 \\ \hhline{~*8{|-}|}
5 & 3 & & \color{blue}\textbf{?} & & \color{blue}\textbf{?} & 3 & & 0 \\ \hhline{~*8{|-}|}
6 & & \color{blue}\textbf{?} & 2 & & 4 & &\color{blue}\textbf{?} & \\ \hhline{~*8{|-}|}
\end{tabular}
谢谢!
答案1
这是我推荐的版本,它根本不使用任何表格,而是一个叫做 Ti 的强大工具钾Z:
\documentclass[tikz]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\sffamily
\begin{tikzpicture}
\matrix (m) [matrix of nodes,nodes in empty cells,nodes={minimum size=.75cm,anchor=center}] {%
& 5 & & 2 & 4 & & & \\
4 & & 3 & 1 & & & 3 & \\
& 5 & 4 & & 5 & & 4 &\\
& & & & & 1 & 1 & 2 \\
3 & & \color{blue}\textbf{?} & & \color{blue}\textbf{?} & 3 & & 0 \\
& \color{blue}\textbf{?} & 2 & & 4 & &\color{blue}\textbf{?} & \\
};
\draw[step=0.75] (m-1-1.north west) grid (m-6-8.south east);
\begin{scope}[font=\scriptsize]
\foreach \i in {1,...,8} \path (m-1-\i.north) node[above] {\i};
\foreach \i in {1,...,6} \path (m-\i-1.west) node[left] {\i};
\end{scope}
\path (m-1-5.north west) node[above=1em] {Movies};
\path (m-3-1.south west) node[left=1em] {Users};
\end{tikzpicture}
\end{document}
我不嵌套表格,而是使用将\multirow
“电影”和“用户”居中:
\documentclass{article}
\usepackage{xcolor}
\usepackage{array}
\usepackage{multirow}
\renewcommand\arraystretch{1.5}
\begin{document}
\sffamily
\begin{tabular}{cc|c|c|c|c|c|c|c|c|}
&\multicolumn{1}{c}{} & \multicolumn{8}{c}{Movies}\\
&\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} \\ \cline{3-10}
\multirow{6}{*}{Users}&1 & & 5 & & 2 & 4 & & & \\ \cline{3-10}
&2 & 4 & & 3 & 1 & & & 3 & \\ \cline{3-10}
&3 & & 5 & 4 & & 5 & & 4 &\\ \cline{3-10}
&4 & & & & & & 1 & 1 & 2 \\ \cline{3-10}
&5 & 3 & & \color{blue}\textbf{?} & & \color{blue}\textbf{?} & 3 & & 0 \\ \cline{3-10}
&6 & & \color{blue}\textbf{?} & 2 & & 4 & &\color{blue}\textbf{?} & \\ \cline{3-10}
\end{tabular}
\end{document}
答案2
您可以嵌套表格。
\documentclass{beamer}
\usepackage{xcolor}
\usepackage{array}
\usepackage{hhline}
\begin{document}
\begin{frame}[t]
\frametitle{Tables can be nested}
\begin{tabular}{cc}
& Movies\\
Users&
\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{|-}|}
1 & & 5 & & 2 & 4 & & & \\ \hhline{~*8{|-}|}
2 & 4 & & 3 & 1 & & & 3 & \\ \hhline{~*8{|-}|}
3 & & 5 & 4 & & 5 & & 4 &\\ \hhline{~*8{|-}|}
4 & & & & & & 1 & 1 & 2 \\ \hhline{~*8{|-}|}
5 & 3 & & \color{blue}\textbf{?} & & \color{blue}\textbf{?} & 3 & & 0 \\ \hhline{~*8{|-}|}
6 & & \color{blue}\textbf{?} & 2 & & 4 & &\color{blue}\textbf{?} & \\ \hhline{~*8{|-}|}
\end{tabular}
\end{tabular}
\end{frame}
\end{document}
答案3
与。{NiceTabular}
nicematrix
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{table}
\centering
\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular}{*{10}{c}}
& & \Block{1-*}{\bfseries \sffamily Movies} \\
& & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
\Block{*-1}{\bfseries \sffamily Users}
& 1 & \Block[hvlines]{*-*}{}
& 5 & & 2 & 4 & & & \\
& 2 & 4 & & 3 & 1 & & & 3 & \\
& 3 & & 5 & 4 & & 5 & & 4 & \\
& 4 & & & & & & 1 & 1 & 2 \\
& 5 & 3 & & \color{blue}\textbf{?} & & \color{blue}\textbf{?} & 3 & & \\
& 6 & & \color{blue}\textbf{?} & 2 & & 4 & & \color{blue}\textbf{?} & \\
\end{NiceTabular}
\end{table}
\end{document}