我正在尝试绘制图片上的内容。绘制两个原始矩阵没有问题,但当涉及到注释时,我就很乱了。
梅威瑟:
\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] {};
\path (m-3-1.south west) node[left=1em] {};
\end{tikzpicture}
\end{document}
答案1
这里有一个很好的shapes.callout
图书馆。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,shapes.callouts}
\begin{document}
\begin{tikzpicture}[node font=\sffamily,note/.style={rectangle callout, fill=#1}]
\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]
\path foreach \i in {1,...,8} {(m-1-\i.north) node[above] {\i}};
\path foreach \i in {1,...,6} {(m-\i-1.west) node[left] {\i}};
\end{scope}
\path (m-1-5.north west) node[above=1em] {};
\path (m-3-1.south west) node[left=1em] {};
\path (m-3-8.east) + (0.3,0.5) node [anchor=south west,
note=blue!50, opacity=.5,callout absolute pointer={(m-3-8.east)}] {Active
user};
\end{tikzpicture}
\end{document}
但既然你提到了“云评论”,我就忍不住要打个广告Kpym 的精彩回答这里。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,decorations.pathreplacing,calc,shadows.blur,shapes}
\tikzset{
% styles to save the path in `\savedpath`
add path/.style = {
decoration={show path construction,
moveto code={
\xdef\savedpath{\savedpath (\tikzinputsegmentfirst)}
},
lineto code={
\xdef\savedpath{\savedpath -- (\tikzinputsegmentlast)}
},
curveto code={
\xdef\savedpath{\savedpath .. controls (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb) ..(\tikzinputsegmentlast)}
},
closepath code={
\xdef\savedpath{\savedpath -- cycle}
}
},
decorate
},
store path/.style = {add path},
store path/.prefix code={\xdef\savedpath{}},
% the style to create the path
callouts/.style={
store path,
append after command={
foreach \target in {#1}{
($(callout)!2pt!-90:\target$)--\target --($(callout)!2pt!90:\target$)
} \savedpath
},
alias=callout
},
% the style to display the callout
custom style/.style={fill=blue!20,text=,blur shadow},
% some fun cloudy node
cloudy/.style={cloud,cloud puffs=10,cloud puff arc=120, aspect=2}
}
\begin{document}
\begin{tikzpicture}[node font=\sffamily,note/.style={rectangle callout, fill=#1}]
\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]
\path foreach \i in {1,...,8} {(m-1-\i.north) node[above] {\i}};
\path foreach \i in {1,...,6} {(m-\i-1.west) node[left] {\i}};
\end{scope}
\path (m-1-5.north west) node[above=1em] {};
\path (m-3-1.south west) node[left=1em] {};
\path[custom style] (m-3-8.east) + (0.3,0.5)
node[right,cloudy,callouts={(m-2-8.east),(m-4-8.east),(m-6-8.east)}]
{many};
\draw[decorate,decoration=brace] (m.south-|m-6-4.east) -- (m.south-|m-6-1.west)
node[midway,below=0.5ex,,align=center] {Calculate \dots\\ Pft \dots};
\end{tikzpicture}
\end{document}