# How to draw honeycomb (line of hexagon)?

How can I draw a series of hexagon with a number inside of every hexagon (multiplication honeycomb)? I didn't find that pattern in logicpuzzle package. Updating: I'm trying to wrtite $2x$ instead +2, $-3x$ instead -3 and $-6x^2$ instead -6, but it doesn't work. Why? I post my code. The hexagons are completely white.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{amsbsy}
\usepackage{amsmath}
\newcommand{\hexmult}{\begin{tikzpicture}[hexa/.style= {shape=regular polygon,regular polygon sides=6,minimum size=1cm, draw,inner sep=0,anchor=south,rotate=30}]
\foreach \j in {1,...,#1}{%
\foreach \i in {1,...,\j}{%
\node[hexa] (h\i;\j) at ({(\i-\j/2)*sin(60)},{\j*0.75}) {};} }
\begin{scope}[execute at begin node=$, execute at end node=$]
\foreach \k/\l in {#2}{\node at (h\k) {\l}; }
\end{scope}
\end{tikzpicture}}

\begin{document}
\hexmult{2}{1;2/$+2$,2;2/{$-3$},1;1/}
\end{document}

• Have you looked here? – Sandy G Nov 19 '17 at 16:49
• thanks for your answer. yes. The problem is that I can't fit the global blue hexagon structure into a structure that I've drawn down. – ryuk Nov 19 '17 at 17:06
• As a rule, packages make some things easier and others harder. There will come a point where you are better off not using a package than using it. – John Kormylo Nov 19 '17 at 17:19
• Don't use $..$. This code automatically parses entries in math mode. Just write \hexmult{2}{1;2/2x,2;2/-3x,1;1/-6x^2}. – Sandy G Jan 15 '18 at 20:32

If you don't mind specifying the numbers backwards:

\documentclass[varwidth,border=5]{standalone}
\usepackage{tikz}
\tikzdeclarecoordinatesystem{hex}{%
\pgfmathsetmacro\y{int(floor(sqrt(2*(#1))+0.5))}%
\pgfmathsetmacro\x{int((\y-1)/2*\y))}%
\pgfpointxy{((#1)-\x-\y/2)* sin(60)}{\y*0.75}}
\tikzset{hex/.style={insert path={[every hex/.try]
(30:1/2) \foreach \j in { 1,...,5} {-- (30+\j*60:1/2) } -- cycle
(0,0) node {$#1$}}}}
\begin{document}
\tikz\foreach \n [count=\i]in {+24,-4,-6,+2,-2,-3,-1,-2,+1,-3}
\path [draw, shift=(hex cs:\i), hex=\n];
\tikz\foreach \n [count=\i]in {-6,+2,-3}
\path [draw, shift=(hex cs:\i), hex=\n];
\tikz[every hex/.style={fill=blue!50!white!50!cyan, draw=white, text=white}]
\foreach \n [count=\i]in {-2,+1,+3,-1,+1,+2}
\path [draw, shift=(hex cs:\i), hex=\n];
\end{document} • Beautiful too your work. +1 – Sebastiano Nov 21 '17 at 8:02 I defined a new command \hexmult that takes 2 arguments. The first is a positive integer giving the number of rows of hexagons. The second is a comma-separated list, where each entry is of the form i;j/k. The j is the row (starting from the bottom), the i is the hexagon number (from the left), and the k is the cell contents, parsed in math mode (so the minus signs look right). You can fill as many of the cells as you like, or none by making the second argument empty.

The grid is a modification of Alain Matthes's solution here.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\newcommand{\hexmult}{\begin{tikzpicture}[hexa/.style= {shape=regular polygon,regular polygon sides=6,minimum size=1cm, draw,inner sep=0,anchor=south,rotate=30}]
\foreach \j in {1,...,#1}{%
\foreach \i in {1,...,\j}{%
\node[hexa] (h\i;\j) at ({(\i-\j/2)*sin(60)},{\j*0.75}) {};} }
\begin{scope}[execute at begin node=$, execute at end node=$]
\foreach \k/\l in {#2}{\node at (h\k) {\l}; }
\end{scope}
\end{tikzpicture}}

\begin{document}
\hexmult{4}{1;4/-1,2;4/-2,3;4/+1,4;4/-3,1;3/+2,2;3/-2,3;3/-3,1;2/-4,2;2/+6,1;1/-24}
\hexmult{3}{1;3/-1,2;3/+1,3;3/+2,2;2/+2}
\hexmult{2}{1;2/+2,2;2/-3,1;1/-6}
\end{document}


Note that you are not restricted to using numbers in the hexes. The code

\hexmult{2}{1;2/2x,2;2/-3x,1;1/-6x^2}


will produce the output: Here's a way to draw your grids "by hand" using Metapost. The links in the comments show you similar approaches in tikz. \RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
pair u, v;
u = 23 right;
v = u rotated 120;
path gon;
gon = for i=0 upto 5: 0.57735026919 u rotated (30 + 60i) -- endfor cycle;

vardef mark(expr x, y, s) =
save p; pair p;
p = origin shifted (x*u) shifted (y*v);
fill gon shifted p withcolor 7/8[blue, white];
draw gon shifted p withcolor 3/4 blue;
label(s, p);
enddef;

mark(0, 0, "$+24$");
mark(0, 1, "$-4$");
mark(1, 1, "$-6$");
mark(0, 2, "$+2$");
mark(1, 2, "$-2$");
mark(2, 2, "$+3$");
mark(0, 3, "$-1$");
mark(1, 3, "$-2$");
mark(2, 3, "$+1$");
mark(3, 3, "$+3$");

endfig;
\end{mplibcode}
\end{document}


This is wrapped up in luamplib so compile with lualatex or adapt for plain MP or gmp package.
{"ft_lang_label":"__label__en","ft_lang_prob":0.5994428,"math_prob":0.9839238,"size":1066,"snap":"2021-31-2021-39","text_gpt3_token_len":400,"char_repetition_ratio":0.08757062,"word_repetition_ratio":0.0,"special_character_ratio":0.36772984,"punctuation_ratio":0.20869565,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99609554,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,2,null,2,null,2,null,2,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-27T20:56:45Z\",\"WARC-Record-ID\":\"<urn:uuid:10896fee-d06b-49be-aa5b-ac0e72d2ee01>\",\"Content-Length\":\"195555\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3dfb3931-69d8-4589-81e7-415507c3fddb>\",\"WARC-Concurrent-To\":\"<urn:uuid:133e6f0a-8616-49b0-8585-c345d1700ac2>\",\"WARC-IP-Address\":\"151.101.129.69\",\"WARC-Target-URI\":\"https://tex.stackexchange.com/questions/402100/how-to-draw-honeycomb-line-of-hexagon/402139\",\"WARC-Payload-Digest\":\"sha1:GYPWUUFX5GQFKZRXNZDKJCRC5W5DIIFS\",\"WARC-Block-Digest\":\"sha1:DN7VJCL2G4Y2C3WHEAA3WQ6V46RTIWSK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046153491.18_warc_CC-MAIN-20210727202227-20210727232227-00140.warc.gz\"}"}