我正在尝试创建以下 14 个点(包括标签)的排列/配置:
我无法做到这一点,我已尝试以下操作:
\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
% labels
\node[right] at ($(circ-5-1) - (0,0.5)$) {$\mathrm{R_2}$};
\node[right] at (circ-5-1) {$\mathrm{L}$};
\node[right] at ($(circ-5-1) + (0,0.5)$) {$\mathrm{R_1}$};
\end{tikzpicture}
它只给我这个配置(我不确定如何“移动”点 $R_1$ 和 $R_2$ 的线):
我知道手绘图是竖着放的,不是横着放的,但我希望排列中的点线是水平的。谢谢。
答案1
像这样吗?
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.5,y={(0cm,-1cm)}]
\foreach \y in {0,1,2}
{% lines
\draw[red] (0,\y) -- (11,\y);
\pgfmathtruncatemacro\xmin{\y*\y-5*\y+7}
\pgfmathtruncatemacro\xmax{-\y*\y-\y+10}
\foreach \x in {\xmin,...,\xmax}
{% dots
\node(circ-\x-\y) [draw,circle,inner sep=1pt,fill] at (\x,\y) {};
}
}
% labels
\node[right] at (11,0) {$\mathrm{R}_1$};
\node[right] at (11,1) {$\mathrm{L}$};
\node[right] at (11,2) {$\mathrm{R}_2$};
\end{tikzpicture}
\end{document}
更新:另一种选择是提供\xmin
和\xmax
值(每行第一个和最后一个点的位置),而不是计算它们。
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.5,y={(0cm,-1cm)}]
\foreach \y/\xmin/\xmax in {0/7/10, 1/3/8, 2/1/4}
{% lines
\draw[red] (0,\y) -- (11,\y);
\foreach \x in {\xmin,...,\xmax}
{% dots
\node(circ-\x-\y) [draw,circle,inner sep=1pt,fill] at (\x,\y) {};
}
}
% labels
\node[right] at (11,0) {$\mathrm{R}_1$};
\node[right] at (11,1) {$\mathrm{L}$};
\node[right] at (11,2) {$\mathrm{R}_2$};
\end{tikzpicture}
\end{document}