送猫出去
答案1
我会使用节点矩阵。您可以通过增加或减少来使其变大或变小\mylength
。
\documentclass{standalone}
\usepackage{tikz}
\usepackage{contour}
\contourlength{1pt}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[font=\sffamily]
\def\mylength{4em}
\matrix[matrix of nodes,column sep=3em,row sep=\mylength,inner sep=0.5*\mylength,
cells={nodes={inner sep=2pt}}](mat){
& A & B \\
1 & $r_{1A}$ & $r_{1B}$\\
2 & $r_{2A}$ & $r_{2B}$\\};
\foreach \X in {1,2}{
\path (mat-\X-3.south) -- (mat-\the\numexpr\X+1\relax-3.north)
coordinate[midway] (auxH-\X)
(mat-2-\X.east) -- (mat-2-\the\numexpr\X+1\relax.west)
coordinate[midway] (auxV-\X);
\draw (mat.west|-auxH-\X) -- (mat.east|-auxH-\X);
\draw (mat.north-|auxV-\X) -- (mat.south-|auxV-\X);}
\draw (mat.south west) -- (mat.south east);
\draw[stealth-stealth] (mat-2-2.north east) -- (mat-2-3.north west)
node[midway,above,scale=0.7] (dAB) {\contour{white}{$d_{AB}$}};
\draw[-stealth] (mat-3-2.south east) -- (mat-3-3.south west);
\draw[-stealth] (mat-2-3) -- (mat-3-3) coordinate[pos=1/3](aux);
\draw[-stealth,densely dotted] (dAB.south) to[out=0,in=80] ++ (1em,-1em)
to[out=-100,in=90]
([xshift=3pt]dAB.south|-mat-3-3);
\draw[stealth-stealth] (mat-2-2.south east) -- (mat-3-2.east)
node[pos=0.5,right,scale=0.7] (d12) {\contour{white}{$d_{12}$}};
\draw[-stealth,densely dotted] (d12.north) to[out=10,in=170] ++ (2em,1em)
to[out=-10,in=180] (aux);
\node[above] at (auxV-2|-mat.north){Movies};
\node[left] at (auxH-2-|mat.west){Users};
\end{tikzpicture}
\end{document}
答案2
添加dashed
虚线:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{array}
\usepackage{contour}
\contourlength{1pt}
\usetikzlibrary{tikzmark}
\begin{document}
\sffamily
\centering\renewcommand{\arraystretch}{2}
\begin{tabular}{rc}
& Movies \\
Users &\centering%\renewcommand{\arraystretch}{3}
\begin{tabular}{ l |>{\centering}p{1cm}| r }
& A & B \\ \hline
1 & $\tikzmarknode{a11}{r_{1A}}$~ & ~$\tikzmarknode{a12}{r_{1B}}$ \\ \hline
2 & $\tikzmarknode{a21}{r_{2A}}$~ & ~$\tikzmarknode{a22}{r_{BA}}$ \\ \hline
\end{tabular}
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
\draw[stealth-stealth,blue] (a11.north east) -- (a12.north west)
node[midway,above,scale=0.7,black] (dAB) {\contour{white}{$d_{AB}$}};
\draw[-stealth,blue] (a21.south east) -- (a22.south west);
\draw[-stealth,blue,dashed] (dAB.south) to[out=0,in=80] (dAB.south|-a22);
\draw[stealth-stealth] (a11.east) -- (a21.east)
node[pos=0.5,right,scale=0.7,black] (d12) {\contour{white}{$d_{12}$}};
\draw[-stealth,dashed] (d12.north) to[out=0,in=180] ([yshift=-1ex]a12.west);
\end{tikzpicture}
\end{document}
或者densely dotted
:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{array}
\usepackage{contour}
\contourlength{1pt}
\usetikzlibrary{tikzmark}
\begin{document}
\sffamily
\centering\renewcommand{\arraystretch}{2}
\begin{tabular}{rc}
& Movies \\
Users &\centering%\renewcommand{\arraystretch}{3}
\begin{tabular}{ l |>{\centering}p{1cm}| r }
& A & B \\ \hline
1 & $\tikzmarknode{a11}{r_{1A}}$~ & ~$\tikzmarknode{a12}{r_{1B}}$ \\ \hline
2 & $\tikzmarknode{a21}{r_{2A}}$~ & ~$\tikzmarknode{a22}{r_{BA}}$ \\ \hline
\end{tabular}
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
\draw[stealth-stealth,blue] (a11.north east) -- (a12.north west)
node[midway,above,scale=0.7,black] (dAB) {\contour{white}{$d_{AB}$}};
\draw[-stealth,blue] (a21.south east) -- (a22.south west);
\draw[-stealth,blue,densely dotted] (dAB.south) to[out=0,in=80] (dAB.south|-a22);
\draw[stealth-stealth] (a11.east) -- (a21.east)
node[pos=0.5,right,scale=0.7,black] (d12) {\contour{white}{$d_{12}$}};
\draw[-stealth,densely dotted] (d12.north) to[out=0,in=180] ([yshift=-1ex]a12.west);
\end{tikzpicture}
\end{document}