绘制六角形网格的问题已在这里讨论:绘制六边形
我希望网格的形状是六边形,而且我希望能够在六边形单元格中添加数字。有什么想法吗?
答案1
我不确定我是否正确理解了这个问题。我忘了在每个单元格中添加姓名。
更新
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture} [hexa/.style= {shape=regular polygon,regular polygon sides=6,minimum size=1cm, draw,inner sep=0,anchor=south,fill=lightgray!85!blue,rotate=30}]
\foreach \j in {0,...,5}{%
\pgfmathsetmacro\end{5+\j}
\foreach \i in {0,...,\end}{%
\node[hexa] (h\i;\j) at ({(\i-\j/2)*sin(60)},{\j*0.75}) {};} }
\foreach \j in {0,...,4}{%
\pgfmathsetmacro\end{9-\j}
\foreach \i in {0,...,\end}{%
\pgfmathtruncatemacro\k{\j+6}
\node[hexa] (h\i;\k) at ({(\i+\j/2-2)*sin(60)},{4.5+\j*0.75}) {};} }
\foreach \k in {0,...,10} {\node [circle,red,minimum size=1cm] at (h3;\k) {3;\k};}
\foreach \k in {0,...,10} {\node [circle,blue,minimum size=1cm] at (h1;\k) {1;\k};}
\end{tikzpicture}
\end{document}
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture} [hexa/.style= {shape=regular polygon,
regular polygon sides=6,
minimum size=1cm, draw,
inner sep=0,anchor=south,
fill=lightgray!85!blue}]
\foreach \j in {0,...,9}{%
\ifodd\j
\foreach \i in {0,...,9}{\node[hexa] (h\j;\i) at ({\j/2+\j/4},{(\i+1/2)*sin(60)}) {\j;\i};}
\else
\foreach \i in {0,...,9}{\node[hexa] (h\j;\i) at ({\j/2+\j/4},{\i*sin(60)}) {\j;\i};}
\fi}
\node [circle,draw,red,minimum size=1cm] at (h3;4){};
\end{tikzpicture}
\end{document}
答案2
不太漂亮,但代码这个答案,如果计算坐标,数字可以相加:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=1cm,y=-1cm]
\foreach \i in {0,...,3}
\foreach \j in {0,...,3} {
\foreach \a in {0,120,-120} \draw (3*\i,2*sin{60}*\j) -- +(\a:1);
\foreach \a in {0,120,-120} \draw (3*\i+3*cos{60},2*sin{60}*\j+sin{60}) -- +(\a:1);}
\foreach \i in {0,...,3}
\foreach \j in {0,...,3} {
\node at (3*\i+2,2*sin{60}*\j) {\small $\i^+,\j$};
\node at (3*\i+0.5,2*sin{60}*\j+sin{60}) {\small $\i,\j$};}
\end{tikzpicture}
\end{document}
所以,如果您只是想对一些六边形进行编号,这可能就足够了。