0

I want to draw the following figure.

enter image description here

But, I only managed to add a layer of hexagons. How to control the addition of other layers?

enter image description here

\documentclass[12pt]{article}

\usepackage{fontspec}

\usepackage[T1]{fontenc}

\usepackage[utf8]{inputenc}

\usepackage[portuguese]{babel}

\usepackage{color}

\usepackage{tikz}

\usepackage{tkz-euclide}

\usetikzlibrary{patterns}

\usetikzlibrary{calc}

\usetikzlibrary{shapes}

\begin{document}

\begin{center}

\begin{tikzpicture}[
    x=7.5mm,y=4.34mm,
    box/.style={
        regular polygon,
        regular polygon sides=6,     
        minimum size=10mm,       
        inner sep=0mm, outer sep=0mm,
        draw}
    ]
    \node [box,fill=black] (innerbox) {};

    \foreach [evaluate=\x as \y using {int(ifthenelse(\x+2>6,\x-4,\x+2))}] \x in {1,...,6}

    \node [box,anchor=corner \y] at (innerbox.corner \x) {};

\end{tikzpicture}

\end{center}

\end{document}

cgnieder
  • 66,645
Benedito Freire
  • 795
  • 6
  • 11

2 Answers2

4

Purely for comparison, here is an alternative using Metapost, some loops, and some colour.

enter image description here

Change the rings variable to control how many rings (or layers) of hexagons are added. Change the colours to suit, or just remove the fill line, if you don't want colour.

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
input colorbrewer-rgb
beginfig(1);
    path h; 
    h = for i=0 upto 5: 17 up rotated 60i -- endfor cycle;
    pair u, v;
    u = point 2 of h - point 0 of h;
    v = u rotated 120;
    numeric rings;  rings = 5;
    for i = 0 upto 5:
        for j = 1 upto rings:
            for k = 0 upto j - 1:
                path t; t = h shifted (j * u + k * v) rotated 60i;
                fill t withcolor Oranges[8][j];
                draw t;
            endfor
        endfor
    endfor
    fill h;
endfig;
\end{mplibcode}
\end{document}

This is wrapped up in luamplib, so you need to compile it with the lualatex engine.

Thruston
  • 42,268
1

Your first image done simply with Mathcha: https://www.mathcha.io/editor

\documentclass[12pt]{article}
\usepackage{tikz}

\begin{document} \tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt

\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1] %uncomment if require: \path (0,300); %set diagram left start at 0, and has height of 300

%Shape: Regular Polygon [id:dp9566546074648377] \draw [fill={rgb, 255:red, 0; green, 0; blue, 0 } ,fill opacity=1 ][line width=1.5] (275,119) -- (296.65,131.5) -- (296.65,156.5) -- (275,169) -- (253.35,156.5) -- (253.35,131.5) -- cycle ; %Shape: Regular Polygon [id:dp4486958110204873] \draw [line width=1.5] (253.35,156.5) -- (275,169) -- (275,194) -- (253.35,206.5) -- (231.7,194) -- (231.7,169) -- cycle ; %Shape: Regular Polygon [id:dp6000238577265022] \draw [line width=1.5] (318.3,119) -- (339.95,131.5) -- (339.95,156.5) -- (318.3,169) -- (296.65,156.5) -- (296.65,131.5) -- cycle ; %Shape: Regular Polygon [id:dp915351643892887] \draw [line width=1.5] (296.65,156.5) -- (318.3,169) -- (318.3,194) -- (296.65,206.5) -- (275,194) -- (275,169) -- cycle ; %Shape: Regular Polygon [id:dp5987225724596497] \draw [line width=1.5] (296.65,81.5) -- (318.3,94) -- (318.3,119) -- (296.65,131.5) -- (275,119) -- (275,94) -- cycle ; %Shape: Regular Polygon [id:dp8189916716968941] \draw [line width=1.5] (231.7,119) -- (253.35,131.5) -- (253.35,156.5) -- (231.7,169) -- (210.05,156.5) -- (210.05,131.5) -- cycle ; %Shape: Regular Polygon [id:dp4670606738503664] \draw [line width=1.5] (361.6,119) -- (383.25,131.5) -- (383.25,156.5) -- (361.6,169) -- (339.95,156.5) -- (339.95,131.5) -- cycle ; %Shape: Regular Polygon [id:dp5621437109282943] \draw [line width=1.5] (188.4,119) -- (210.05,131.5) -- (210.05,156.5) -- (188.4,169) -- (166.75,156.5) -- (166.75,131.5) -- cycle ; %Shape: Regular Polygon [id:dp6599968429743048] \draw [line width=1.5] (210.05,81.5) -- (231.7,94) -- (231.7,119) -- (210.05,131.5) -- (188.4,119) -- (188.4,94) -- cycle ; %Shape: Regular Polygon [id:dp5494891870772345] \draw [line width=1.5] (253.35,81.5) -- (275,94) -- (275,119) -- (253.35,131.5) -- (231.7,119) -- (231.7,94) -- cycle ; %Shape: Regular Polygon [id:dp7594270518236381] \draw [line width=1.5] (339.95,81.5) -- (361.6,94) -- (361.6,119) -- (339.95,131.5) -- (318.3,119) -- (318.3,94) -- cycle ; %Shape: Regular Polygon [id:dp7542566297595752] \draw [line width=1.5] (210.05,156.5) -- (231.7,169) -- (231.7,194) -- (210.05,206.5) -- (188.4,194) -- (188.4,169) -- cycle ; %Shape: Regular Polygon [id:dp13329549779333316] \draw [line width=1.5] (339.95,156.5) -- (361.6,169) -- (361.6,194) -- (339.95,206.5) -- (318.3,194) -- (318.3,169) -- cycle ; %Shape: Regular Polygon [id:dp2175531439213112] \draw [line width=1.5] (231.7,194) -- (253.35,206.5) -- (253.35,231.5) -- (231.7,244) -- (210.05,231.5) -- (210.05,206.5) -- cycle ; %Shape: Regular Polygon [id:dp18515279548847507] \draw [line width=1.5] (275,194) -- (296.65,206.5) -- (296.65,231.5) -- (275,244) -- (253.35,231.5) -- (253.35,206.5) -- cycle ; %Shape: Regular Polygon [id:dp05008914090789984] \draw [line width=1.5] (318.3,194) -- (339.95,206.5) -- (339.95,231.5) -- (318.3,244) -- (296.65,231.5) -- (296.65,206.5) -- cycle ; %Shape: Regular Polygon [id:dp7243060183264154] \draw [line width=1.5] (231.7,44) -- (253.35,56.5) -- (253.35,81.5) -- (231.7,94) -- (210.05,81.5) -- (210.05,56.5) -- cycle ; %Shape: Regular Polygon [id:dp20654389275063734] \draw [line width=1.5] (275,44) -- (296.65,56.5) -- (296.65,81.5) -- (275,94) -- (253.35,81.5) -- (253.35,56.5) -- cycle ; %Shape: Regular Polygon [id:dp7883357127939892] \draw [line width=1.5] (318.3,44) -- (339.95,56.5) -- (339.95,81.5) -- (318.3,94) -- (296.65,81.5) -- (296.65,56.5) -- cycle ; \end{tikzpicture}

\end{document}

enter image description here

Sebastiano
  • 54,118