變更矩陣樣式

變更矩陣樣式

我有以下矩陣及其各自的程式碼。附圖顯示了輸出。由於我必須將這個圖像放入學術論文中,我認為我的實際設計有點過分,就風格、意義而言,我需要讓它看起來更「數學」。

\documentclass{standalone}
%\usepackage[showframe]{geometry}
\usepackage{tikz}
\definecolor{gris}{RGB}{250,250,250}
\usepackage{lmodern}
\usetikzlibrary{matrix,
    positioning}
\tikzset{
    mymatrix/.style = {matrix of nodes,
        nodes in empty cells,
        nodes={minimum height=3ex, minimum width=1em,
            inner sep=0pt, outer sep=0pt, anchor=center,
            draw, very thin,scale=0.8,transform shape},
        column sep=0pt,
        row sep=0pt,
        inner sep=0.5\pgflinewidth, outer sep=1pt,
        draw, thick},
    empty node/.style = {draw,fill=gris},
    every label/.append style = {font=\large, text=teal}
}
\makeatletter
\def\tikz@lib@matrix@empty@cell{%
    \iftikz@lib@matrix@empty%
    \node[name=\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn,empty node]{};\fi}
\makeatother

\usepackage{bm}
\newcommand{\MatrixVariable}[1]{\bm{{#1}}}

\begin{document}

    \begin{tikzpicture}[node distance=0pt,scale=0.6,nodes={transform
        shape}]
    \matrix (m1) [mymatrix,
    label={[rotate=90, anchor=south,black]left: Movies},
    label={[black]below:$\MatrixVariable{{R}}$},
    label={[black]above:Users},
    nodes={fill=gray!30}]
    {
        1   &   & 3 &   &   & 5 &   &   & 5 &   & 4 &   \\
        &   & 5 & 4 &   &   & 4 &   &   & 2 & 1 & 3 \\
        2   & 4 &   & 1 & 2 &   & 3 &   & 4 & 3 & 5 &   \\
        & 2 & 4 &   & 5 &   &   & 4 &   &   & 2 &   \\
        &   & 4 & 3 & 4 & 2 &   &   &   &   & 2 & 5 \\
        1   &   & 3 &   & 3 &   &   & 2 &   &   & 4 &   \\
    };
    \node (approx) [right=of m1,scale=2] {$\approx$};
    \matrix (m2) [mymatrix=none, right=0.1em of approx,
    label={[rotate=90, anchor=south east,xshift=-0.7em,black]left: Movies},
    label={[black]below:$\MatrixVariable{{Q}}$},
    label={[black]above:$f$-factors},
    nodes={minimum width=2.2em,fill=white}]
    {
        0.1& -0.4  & -0.2 \\
        -0.5& 0.6 & 0.5 \\
        -0.2& 0.3 &0.5  \\
        1.1& 2.1 & 0.3 \\
        -0.7&2.1  & -2 \\
        -1& 0.7 & 0.3 \\
    };
    \node (times) [right=of m2,scale=2] {$\cdot$};
    \matrix (m3) [mymatrix=none, right=of times,
    label={[rotate=90, anchor=north,black]right: $f$-factors},
    label={[black]below:$\MatrixVariable{{P}^{T}}$},
    label={[black]above:Users},
    nodes={minimum width=2em,fill=white}]
    {
        1.1&-2  & 0.3 & 0.5 &-2  &  -0.5 & 0.8 & -0.4 & 0.3 & 1.4 & 2.4 &  -0.9\\
        -0.8& 0.7 & 0.5 & 1.4 &0.3  & -1 & 1.4 & 2.9 & 0.7 & - 1.2 & 1.3& 0.4\\
        2.1& -0.4 & 0.6 & 1.7 & 2.4 & 0.9 & -0.3 & 0.4 &  0.8 &   0.7 & -0.6&0.1 \\
    };
    \end{tikzpicture}

\end{document}

在此輸入影像描述

這就是我的想法:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \[
    \begin{pmatrix}
    x_{11}       & x_{12} & x_{13} & \dots & x_{1n} \\
    x_{21}       & x_{22} & x_{23} & \dots & x_{2n} \\
    \hdotsfor{5} \\
    x_{d1}       & x_{d2} & x_{d3} & \dots & x_{dn}
    \end{pmatrix}
    =
    \begin{pmatrix}
    x_{11} & x_{12} & x_{13} & \dots  & x_{1n} \\
    x_{21} & x_{22} & x_{23} & \dots  & x_{2n} \\
    \vdots & \vdots & \vdots & \ddots & \vdots \\
    x_{d1} & x_{d2} & x_{d3} & \dots  & x_{dn}
    \end{pmatrix}
    \]
\end{document}

在此輸入影像描述

我在使用“電影”、“用戶”和“因素”標籤時遇到一些問題。你能幫我解決這個問題嗎?

ps:我也考慮過這個,但是如果能添加更多的 k 因子就更好了:

在此輸入影像描述

答案1

使用arrayrotatebox

在此輸入影像描述

微量元素

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\begin{document}
\[\begin{array}{ccc}
 \text{Users} & &  \text{factors}\\
    \rotatebox[origin=c]{90}{\text{Movies}}
    \begin{pmatrix}
    x_{11}       & x_{12} & x_{13} & \dots & x_{1n} \\
    x_{21}       & x_{22} & x_{23} & \dots & x_{2n} \\
    \hdotsfor{5} \\
    x_{d1}       & x_{d2} & x_{d3} & \dots & x_{dn}
    \end{pmatrix}
    &=&
    \rotatebox[origin=c]{90}{\text{Movies}}
    \begin{pmatrix}
    x_{11} & x_{12} & x_{13} & \dots  & x_{1n} \\
    x_{21} & x_{22} & x_{23} & \dots  & x_{2n} \\
    \vdots & \vdots & \vdots & \ddots & \vdots \\
    x_{d1} & x_{d2} & x_{d3} & \dots  & x_{dn}
    \end{pmatrix}
\end{array}\]
\end{document}

答案2

也許你喜歡:

在此輸入影像描述

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \[
    \underbrace{\!
    \begin{pmatrix}
    x_{11} & x_{12} & \dots  & x_{1n} \\
    x_{21} & x_{22} & \dots  & x_{2n} \\
    \vdots & \vdots & \ddots & \vdots \\
    x_{d1} & x_{d2} & \dots  & x_{dn}
    \end{pmatrix}\!
    }_{\mathbf{R}_{\text{Movies}\times \text{Users}}}
    \approx
    \underbrace{\!
    \begin{pmatrix}
    y_{11} & y_{12} & \dots  & y_{1n} \\
    y_{21} & y_{22} & \dots  & y_{2n} \\
    \vdots & \vdots & \ddots & \vdots \\
    y_{d1} & y_{d2} & \dots  & y_{dn}
    \end{pmatrix}\!
    }_{\mathbf{Q}_{\text{Movies}\times f\text{-factors}}}
    \cdot
    \underbrace{
    \begin{pmatrix}\!
    z_{11} & z_{12} & \dots  & z_{1n} \\
    z_{21} & z_{22} & \dots  & z_{2n} \\
    \vdots & \vdots & \ddots & \vdots \\
    z_{d1} & z_{d2} & \dots  & z_{dn}
    \end{pmatrix}\!
    }_{\mathbf{P}^T_{f\text{-factors}\times\text{Users}}}
    \]
\end{document}

相關內容