答案1
这里我使用了 hexboard 包。绘制棋盘 ( \hexboard
) 和为单元格着色 ( \hexcellshaded
) 是 hexboard 的一部分。该包还有一个\hexconnect
用于在两个单元格之间绘制线条的命令,不过我在这里重写了这个命令,以便dotted
线条变成虚线。然后,绘制单元格边框的代码在这里是新的,不过是基于 hexboard 中绘制彩色边缘边界的代码。
\documentclass{standalone}
\usepackage{hexboard}
% this redefines the hexboard command \hexconnect so that it has a dotted line instead of a solid one. The difference is ',dotted' in the \draw command
\renewcommand{\hexconnect}[4]{%
\hexcoord{#1}{#2}
\node[minimum size=0,inner sep=0,outer sep=0] (A) at (\xchor em,\ychor em) {};
\hexcoord{#3}{#4}
\node[minimum size=0,inner sep=0,outer sep=0] (B) at (\xchor em,\ychor em) {};
\draw[line width=\hexthinline em,line cap=round,dotted] (A) -- (B);
}
% these commands are based on the code that draws the coloured edge borders in hexboard
% they draw the six parts of a cell border for the cell specified by the two arguments
\newcommand{\bottomrightcellborder}[2]{\hexcoord{#1}{#2}\draw[black,shift={(\xchor em,\ychor em)},line width=\hexedgewidth em,line cap=round] (0 em,-0.577350 em) -- (0.5 em,-0.288675 em);}
\newcommand{\bottomleftcellborder}[2]{\hexcoord{#1}{#2}\draw[black,shift={(\xchor em,\ychor em)},line width=\hexedgewidth em,line cap=round] (-0.5 em,-0.288675 em) -- (0 em,-0.577350 em);}
\newcommand{\toprightcellborder}[2]{\hexcoord{#1}{#2}\draw[black,shift={(\xchor em,\ychor em)},line width=\hexedgewidth em,line cap=round] (0 em,0.577350 em) -- (0.5 em,0.288675 em);}
\newcommand{\topleftcellborder}[2]{\hexcoord{#1}{#2}\draw[black,shift={(\xchor em,\ychor em)},line width=\hexedgewidth em,line cap=round] (-0.5 em,0.288675 em) -- (0 em,0.577350 em);}
\newcommand{\leftcellborder}[2]{\hexcoord{#1}{#2}\draw[black,shift={(\xchor em,\ychor em)},line width=\hexedgewidth em,line cap=round] (-0.5 em,-0.288675 em) -- (-0.5 em,0.288675 em);}
\newcommand{\rightcellborder}[2]{\hexcoord{#1}{#2}\draw[black,shift={(\xchor em,\ychor em)},line width=\hexedgewidth em,line cap=round] (0.5 em,-0.288675 em) -- (0.5 em,0.288675 em);}
\usetikzlibrary{arrows.meta} % a hexpicture environment is really a tikzpicture environment, so we can use tikz arrows.meta to draw arrowheads
\begin{document}
\begin{hexpicture}
% shade some cells
% \hexcellshaded is a hexboard command that draws a shaded cell. We do it before drawing the actual \hexboard so that the edge border of the \hexboard is above the shading.
\hexcellshaded{a}{1}
\hexcellshaded{a}{2}
\hexcellshaded{a}{5}
\hexcellshaded{b}{3}
\hexcellshaded{b}{4}
\hexcellshaded{b}{5}
\hexcellshaded{b}{6}
\hexcellshaded{c}{1}
\hexcellshaded{c}{2}
\hexcellshaded{c}{5}
\hexcellshaded{d}{1}
\hexcellshaded{d}{3}
\hexcellshaded{d}{5}
\hexcellshaded{e}{2}
\hexcellshaded{e}{6}
\hexcellshaded{f}{1}
\hexcellshaded{f}{2}
\hexcellshaded{f}{4}
\hexcellshaded{f}{5}
% draw the board
\hexboard{6}
% draw a path across the board
% \hexconnect is a hexboard command that connects two cells. The cell coordinates don't have to refer to a cell that is actually drawn on the board, as in references to e0 and d7 etc.
\hexconnect{e}{0}{e}{1}
\hexconnect{e}{1}{d}{2}
\hexconnect{d}{2}{c}{3}
\hexconnect{c}{3}{c}{4}
\hexconnect{c}{4}{d}{4}
\hexconnect{d}{4}{e}{3}
\hexconnect{e}{3}{f}{3}
\hexconnect{f}{3}{e}{4}
\hexconnect{e}{4}{e}{5}
\hexconnect{e}{5}{d}{6}
\hexconnect{d}{6}{d}{7}
\hexconnect{d}{7}{e}{7}
\hexconnect{e}{7}{f}{6}
% \hexconnect{f}{6}{f}{7} % this would draw the last line off the board, but I've replaced it with the arrow head command below
% draw thick border around the right hand side of the path across the board
% using the custom border commands to draw partial borders around the needed cells
\toprightcellborder{g}{0}
\bottomrightcellborder{f}{1}
\bottomleftcellborder{f}{1}
\leftcellborder{f}{1}
\bottomleftcellborder{e}{2}
\leftcellborder{e}{2}
\toprightcellborder{e}{2}
\bottomleftcellborder{d}{3}
\leftcellborder{d}{3}
\topleftcellborder{d}{3}
\toprightcellborder{d}{3}
\rightcellborder{d}{3}
\topleftcellborder{f}{2}
\bottomleftcellborder{f}{3}
\bottomrightcellborder{f}{3}
\rightcellborder{f}{3}
\bottomleftcellborder{f}{4}
\leftcellborder{f}{4}
\topleftcellborder{f}{4}
\leftcellborder{f}{5}
\toprightcellborder{f}{5}
\bottomleftcellborder{e}{6}
\leftcellborder{e}{6}
\topleftcellborder{e}{6}
\toprightcellborder{e}{6}
\rightcellborder{e}{6}
\bottomrightcellborder{f}{6}
\rightcellborder{f}{6}
% \bottomrightcellborder{f}{7} % this would draw the last line off the board, but I've replaced it with the arrow head command below
% draw arrow heads pointing off the board
% this is a custom version of the hexboard command \hexconnect with an extra arrowhead from arrows.meta
% \hexcoord sets \xchor and \ychor to be the centre of the given cell. Then we set two nodes and draw a line between them
\hexcoord{f}{6}
\node[minimum size=0,inner sep=0,outer sep=0] (A) at (\xchor em,\ychor em) {};
\hexcoord{f}{7}
\node[minimum size=0,inner sep=0,outer sep=0] (B) at (\xchor em,\ychor em) {};
\draw[line width=\hexthinline em,line cap=round,dotted,-{Stealth[open]}] (A) -- (B);
% this is a custom version of \bottomrightcellborder with an extra arrowhead from arrows.meta
\hexcoord{f}{7}
\draw[black,shift={(\xchor em,\ychor em)},line width=\hexedgewidth em,line cap=round,-{Stealth[length=2mm, width=2mm]}] (0 em,-0.577350 em) -- (0.5 em,-0.288675 em);
\end{hexpicture}
\end{document}