我希望有一个带有标签的点或点的网格,并将它们组合成如下所示的图形。
我尝试了最接近左上角第一个网格的图表,这是它的结果,
\documentclass{article}
\usepackage{tikz}
\begin{tikzpicture}
\foreach \x in {0,1,2,3,4,5,6}
\foreach \y in {0,1,2,3,4,5,6}
{
\draw (\x,\y) circle (0.3cm);
}
\fill (3,4) node {\textbf{A}};
\fill (4,3) node {\textbf{B}};
\fill (3,3) node {\textbf{X}};
\fill (3,2) node {\textbf{C}};
\fill (2,3) node {\textbf{D}};
\end{tikzpicture}
\end{document}
如果您能帮助我找到二维和一维网格的代码,我将非常高兴。
先感谢您!
答案1
这不像 cmhughes 的答案那么优雅。您还可以使用shift
s 和scope
s 来定位图形。
代码
%\documentclass{article}
\documentclass[border=5,convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}
\tikzset{circle node/.style = {circle,inner sep=1pt,draw, fill=white},
X node/.style = {fill=white, inner sep=1pt},
dot node/.style = {circle, draw, inner sep=5pt}
}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\foreach \x in {0,...,6}
\foreach \y in {0,...,6}
{
\fill (\x,\y) circle (2pt);
}
\foreach \a/\b/\c in {3/4/A,4/3/B,3/2/C,2/3/D}
\fill (\a,\b) node (\c) [circle node] {\textbf{\c}};
\node [X node] at (3,3) {\textbf{X}};
\node at (11,3) {FIRST ORDER};
\begin{scope}[shift={(15,3)}]
\foreach \x in {0,...,8}
\fill (\x,0) circle (2pt);
\node at (4,0) [X node] {\textbf{X}};
\foreach \x in {3,5}
\node [dot node] at (\x,0) {};
\end{scope}
\begin{scope}[shift={(0,-8)}]
\foreach \x in {0,...,6}
\foreach \y in {0,...,6}
{
\fill (\x,\y) circle (2pt);
}
\foreach \a/\b/\c in {2/4/E,4/4/F,4/2/G,2/2/H}
\fill (\a,\b) node [circle node] {\textbf{\c}};
\node [X node] at (3,3) {\textbf{X}};
\node at (11,3) {SECOND ORDER};
\begin{scope}[shift={(15,3)}]
\foreach \x in {0,...,8}
\fill (\x,0) circle (2pt);
\node at (4,0) [X node] {\textbf{X}};
\foreach \x in {2,6}
\node [dot node] at (\x,0) {};
\end{scope}
\end{scope}
\end{tikzpicture}
\end{document}
输出
答案2
以下是一些入门知识
思路是nodes
使用foreach
命令进行设置,并将它们命名为x-y
。然后您可以圈出相应的节点。
坐标系起始于 ,(0,0)
最高可达。您可以根据需要(8,8)
调整。scale
\documentclass{article}
\usepackage{tikz}
\tikzset{mystyle/.style={shape=circle,fill=black,scale=0.3}}
\tikzset{withtext/.style={fill=white}}
\begin{document}
\begin{figure}
\begin{minipage}{.5\textwidth}
\begin{tikzpicture}[scale=.5]
% setup the nodes
\foreach \x in {0,...,8}
\foreach \y in {0,...,8}
{
\ifnum\x=4
\ifnum\y=4
\node (\x-\y) at (\x,\y){X};
\else
\node[mystyle] (\x-\y) at (\x,\y){};
\fi
\else
\node[mystyle] (\x-\y) at (\x,\y){};
\fi
}
% circle selected nodes with letters
\foreach \mynode/\mytext in {4-3/A,3-4/B,5-4/C,4-5/D}
{
\draw[withtext] (\mynode) circle (0.4cm) node {\mytext};
}
\end{tikzpicture}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\begin{tikzpicture}[scale=.5]
% setup the nodes
\foreach \x in {0,...,8}
{
\ifnum\x=4
\node (\x) at (\x,0){X};
\else
\node[mystyle] (\x) at (\x,0){};
\fi
}
% circle selected nodes
\foreach \mynode in {3,5}
{
\draw (\mynode) circle (0.3cm);
}
\end{tikzpicture}
\end{minipage}%
\end{figure}
\end{document}