图像尺寸不适合

图像尺寸不适合

你能帮我解决下面图片的尺寸问题吗?

\documentclass{article}
\usepackage{tikz}
\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, fill=yellow},
                      column sep=0pt,
                      row sep=0pt,
                      inner sep=0.5\pgflinewidth, outer sep=1pt,
                      draw, thick},
 empty node/.style = {draw,fill=none},
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

\begin{document}
    \[
    \begin{tikzpicture}[node distance=0pt]
\matrix (m1) [mymatrix,
              label={[rotate=90, anchor=south]left: items},
              label=below:$R$,
              label=above:users]
{
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] {$\approx$};
\matrix (m2) [mymatrix=none, right=1em of approx,
              label={[rotate=90, anchor=south,,xshift=-2em]left: items},
              label=below:$Q$,
              label=above:factors,
              nodes={minimum width=2em,fill=none}]
{
    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] {$\cdot$};
\matrix (m3) [mymatrix=none, right=of times,
              label={[rotate=90, anchor=north]right: factors},
              label=below:$P^T$,
              label=above:users,
              nodes={minimum width=2em,fill=none}]
{
 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 & .9 & -0.3 & 0.4 &  0.8 &   0.7 & -0.6&0.1 \\
};
\end{tikzpicture}
\]
\end{document}

在此处输入图片描述

答案1

选项包括使图片更经济、缩放图片、增加文本宽度以及不将其放在环境中\[...\]。每个选项都有一些作用。

\documentclass{article}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{tikz}
\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},
                      column sep=0pt,
                      row sep=0pt,
                      inner sep=0.5\pgflinewidth, outer sep=1pt,
                      draw, thick},
 empty node/.style = {draw,fill=none},
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

\begin{document}

\noindent\begin{tikzpicture}[node distance=0pt,scale=0.49,transform shape]
\matrix (m1) [mymatrix,
              label={[rotate=90, anchor=south]left: items},
              label=below:$R$,
              label=above:users,
              nodes={fill=yellow}]
{
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] {$\approx$};
\matrix (m2) [mymatrix=none, right=0.1em of approx,
              label={[rotate=90, anchor=south east,xshift=-0.7em]left: items},
              label=below:$Q$,
              label=above:factors,
              nodes={minimum width=2.2em}]
{
    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] {$\times$};
\matrix (m3) [mymatrix=none, right=of times,
              label={[rotate=90, anchor=north]right: factors},
              label=below:$P^T$,
              label=above:users,
              nodes={minimum width=2em,fill=none}]
{
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 & .9 & -0.3 & 0.4 &  0.8 &   0.7 & -0.6&0.1 \\
};
\end{tikzpicture}
\end{document}

在此处输入图片描述

showframe只是为了引导视线而添加的。您可以只用两行写出该方程式。

或者,按照您的建议,将文本变小一些。

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{tikz}
\usetikzlibrary{matrix,
                positioning}
\tikzset{
    mymatrix/.style = {matrix of math 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.75,transform shape},
                      column sep=0pt,
                      row sep=0pt,
                      inner sep=0.5\pgflinewidth, outer sep=1pt,
                      draw, thick},
 empty node/.style = {draw,fill=none},
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

\begin{document}

\[\begin{tikzpicture}[node distance=0pt,scale=0.75,nodes={transform
shape}]
\matrix (m1) [mymatrix,
              label={[rotate=90, anchor=south]left: items},
              label=below:$R$,
              label=above:users,
              nodes={fill=yellow}]
{
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] {$\approx$};
\matrix (m2) [mymatrix=none, right=0.1em of approx,
              label={[rotate=90, anchor=south east,xshift=-0.7em]left: items},
              label=below:$Q$,
              label=above:factors,
              nodes={minimum width=2.4em}]
{
    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] {$\times$};
\matrix (m3) [mymatrix=none, right=of times,
              label={[rotate=90, anchor=north]right: factors},
              label=below:$P^T$,
              label=above:users,
              nodes={minimum width=2.4em,fill=none}]
{
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 & .9 & -0.3 & 0.4 &  0.8 &   0.7 & -0.6&0.1 \\
};
\end{tikzpicture}\]

\end{document}

在此处输入图片描述

相关内容