![向方格网格的子集添加标签和彩色线条](https://linux22.com/image/432348/%E5%90%91%E6%96%B9%E6%A0%BC%E7%BD%91%E6%A0%BC%E7%9A%84%E5%AD%90%E9%9B%86%E6%B7%BB%E5%8A%A0%E6%A0%87%E7%AD%BE%E5%92%8C%E5%BD%A9%E8%89%B2%E7%BA%BF%E6%9D%A1.png)
我知道如何在乳胶上生成方形网格,但我想知道是否有办法在图像中绘制带有给定标签 ($R_1$、$N$ 和 $R_2$) 的集合?我还想看看是否有办法绘制此图片中看到的绿线和蓝线。
我能够生成图表所需的点
\begin{tikzpicture}
\clip (-1,-1) rectangle (6cm,6cm);
\foreach \x in {1,2,3,4}
{
\foreach \y in {0,1,2}
{
\node[draw,circle,inner sep=1pt,fill] at (.5*\x,.5*\y) {};
}
}
\foreach \x in {0,5}{
\foreach \y in {1}{
\node[draw,circle,inner sep=1pt,fill] at (.5*\x,.5*\y) {};
}
}
\end{tikzpicture}
但我正在努力添加蓝线和绿线以及标签。
答案1
我将为每个节点命名\node(name)[...] {label}
,然后画线并添加标签。
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\foreach \x in {1,...,4}{
\foreach \y in {0,...,2}{
\node(circ-\x-\y)[draw,circle,inner sep=1pt,fill] at (.5*\x,.5*\y) {};
}
}
\foreach \x in {0,5}{
\foreach \y in {1}{
\node(circ-\x-\y)[draw,circle,inner sep=1pt,fill] at (.5*\x,.5*\y) {};
}
}
% lines
\foreach \i [evaluate=\i as \j using int(\i+1)] in {2,...,4}{
\draw[green!50!black] (circ-1-0) -- (circ-\i-2);
\draw[blue!50!black] (circ-1-0) -- (circ-\j-1);
}
% labels
\node[right] at ($(circ-5-1) - (0,0.5)$) {$\mathrm{R_2}$};
\node[right] at (circ-5-1) {$\mathrm{N}$};
\node[right] at ($(circ-5-1) + (0,0.5)$) {$\mathrm{R_1}$};
\end{tikzpicture}
\end{document}