我是乳胶新手,我需要你帮助我完成下图中的矩阵:
姆韦
\documentclass{article}
\usepackage{amsmath,blkarray}
\begin{document}
\[
\begin{blockarray}{ccccc}
\begin{block}{c(cccc)}
a & 2173.00 & 354.00 & 0.00 & 1249.00\smash[b]{\vphantom{\Big|}} \\
b & 0.00 & 3772.00 & 52.00 & 0.00 \\
c & 474.00 & 469.00 & 2858.00 & 42.00 \\
d & 1262.00 & 303.00 & 39.00 & 2180.00\smash[t]{\vphantom{\Big|}}\\
\end{block}
& a & b & c & d
\end{blockarray}
\]
\end{document}
答案1
欢迎使用 TeX-SE!您已经拥有一切,只需对布局进行微小调整,并更改单元格的内容。
\documentclass{article}
\usepackage{amsmath,blkarray}
\begin{document}
\[
\begin{blockarray}{lccc}
\text{Ratings} & \text{book}_1 & \text{book}_2 & \text{book}_3 \\
\begin{block}{l(ccc)}
\text{user}_1 & - & 1 & - \smash[b]{\vphantom{\Big|}}\\
\text{user}_2 & - & 5 & - \\
\text{user}_3 & 4 & - & - \\
\text{user}_4 & - & - & 2\smash[t]{\vphantom{\Big|}}\\
\end{block}
\end{blockarray}
\]
\end{document}
您可以将用户和书籍文本设为斜体(感谢@naveganTeX 提出这一点!)。
\documentclass{article}
\usepackage{amsmath,blkarray}
\begin{document}
\[
\begin{blockarray}{lccc}
\text{Ratings} & \textit{book}_1 & \textit{book}_2 & \textit{book}_3 \\
\begin{block}{l(ccc)}
\textit{user}_1 & - & 1 & - \smash[b]{\vphantom{\Big|}}\\
\textit{user}_2 & - & 5 & - \\
\textit{user}_3 & 4 & - & - \\
\textit{user}_4 & - & - & 2\smash[t]{\vphantom{\Big|}}\\
\end{block}
\end{blockarray}
\]
\end{document}
一个非常快速编写的tikz
版本:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\begin{document}
\begin{tikzpicture}
\matrix [matrix of math nodes,left delimiter=(,right delimiter=),
row sep=0.2em,column sep=2em] (m) {
- & 1 & - \\
- & 5 & - \\
4 & - & - \\
- & - & 2\\};
\foreach \X in {1,...,4}
{\node[anchor=east] (u\X) at ([xshift=-1em]m.west|-m-\X-1){$\text{user}_\X$};}
\foreach \X in {1,...,3}
{\node[anchor=south] (b\X) at ([yshift=0.5em]m.north-|m-1-\X){$\text{book}_\X$};}
\draw ([yshift=0.3em]m.north west) -- ++ (-4em,1em);
\node[anchor=south east] at ([yshift=0.02em]u1.north east) {Ratings};
\node[left=0.02em of b1,yshift=0.5em] {Movies};
\end{tikzpicture}
\end{document}