![如何用 TikZ 绘制硅晶格(原为:如何在 LaTex 中生成此图像)](https://linux22.com/image/419327/%E5%A6%82%E4%BD%95%E7%94%A8%20TikZ%20%E7%BB%98%E5%88%B6%E7%A1%85%E6%99%B6%E6%A0%BC%EF%BC%88%E5%8E%9F%E4%B8%BA%EF%BC%9A%E5%A6%82%E4%BD%95%E5%9C%A8%20LaTex%20%E4%B8%AD%E7%94%9F%E6%88%90%E6%AD%A4%E5%9B%BE%E5%83%8F%EF%BC%89.png)
答案1
你可以使用 TikZ 矩阵。然后像这样:
\documentclass[margin=5mm, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{backgrounds}
\begin{document}
\pgfmathsetlengthmacro\eradius{0.65ex}
\begin{tikzpicture}[
si/.style={circle, draw, fill=white},
]
\matrix (m) [matrix of nodes, nodes in empty cells,
nodes={inner sep=1ex, anchor=center},
column sep=2em, row sep=2em,
]{
& & & & & & \\
& |[si]|Si & & |[si]|Si & & |[si]|Si & \\
& & & & & & \\
& |[si]|Si & & |[si]|Si & & |[si]|Si & \\
& & & & & & \\
%1 & 2 & 3 & 4 & 5 & 6 & 7 \\
};
% Annotations
\foreach \y in {1,3,5}{
\foreach \x in {2,4,6}{
\fill[] ([yshift=0.2*\eradius]m-\y-\x.north) circle[radius=\eradius];
\fill[] ([yshift=-0.2*\eradius]m-\y-\x.south) circle[radius=\eradius];
}}
\foreach \y in {2,4}{
\foreach \x in {1,3,5,7}{
\fill[] ([xshift=0.2*\eradius]m-\y-\x.east) circle[radius=\eradius];
\fill[] ([xshift=-0.2*\eradius]m-\y-\x.west) circle[radius=\eradius];
}}
\begin{scope}[on background layer]
\foreach \y in {2,4}{
\draw[transform canvas={yshift=1ex},
shorten >=-1.5ex, shorten <=-1.5ex
] (m-\y-1.north west) -- (m-\y-7.north east);
\draw[transform canvas={yshift=-1ex},
shorten >=-1.5ex, shorten <=-1.5ex
] (m-\y-1.south west) -- (m-\y-7.south east);
}
\foreach \x in {2,4,6}{
\draw[transform canvas={xshift=-0.7ex},
shorten >=-1.5ex, shorten <=-1.5ex
] (m-1-\x.north west) -- (m-5-\x.south west);
\draw[transform canvas={xshift=0.7ex},
shorten >=-1.5ex, shorten <=-1.5ex
] (m-1-\x.north east) -- (m-5-\x.south east);
}
\end{scope}
\end{tikzpicture}
\end{document}