1

I want to know if it's possible to do an arrow of a walkthrough of an Hex board game using the hexgame package. Anyone knows a way to do this?

The idea is to make something like the arrow in this link:

enter image description here

But doing in the package hexgame, that shows a board like this:

enter image description here

If it's not possible to do in the hexgame package, how can I do the first image in Latex code considering the arrow and the thick black line?

3
  • 4
    Could you lay the foundation of what you're talking about by means of a working minimal example?
    – Werner
    Jun 30, 2016 at 7:17
  • In fact the only thing I have about that images is a latex package. That's the reason of why I want to know how to do those images and why I don't have a code to show.
    – iam_agf
    Nov 17, 2016 at 18:22
  • It's doable, as was shown below with the hexboard package. It's basictikz . I suggest spending some time on the minimal document and more specialized on the big manual found at: ctan.org/pkg/pgf?lang=de .
    – MS-SPO
    Jun 10, 2022 at 7:08

1 Answer 1

3

Here I use the package hexboard. Drawing the board (\hexboard) and shading the cells (\hexcellshaded) are part of hexboard. That package also has a command \hexconnect for drawing a line between two cells, though here I rewrite this command to add dotted so the line is dotted. Then the code for drawing cell borders is new here, though based on the code in hexboard that draws the coloured edge boundaries.

Hex board with labelling as described in the question

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .