1

I am trying to draw three variations of hexagonal chains where there is a finite number of hexagons in each chain. It'll look something like a path graph of hexagons.

How would I draw three hexagons in chains where they share a different number of edges like in the photo?

three chains

Thank you so much!

5 Answers 5

4

What you want looks a lot like organic chemistry.

In this case, you can use "chemfig"

\documentclass[border=5pt]{standalone}
\usepackage{chemfig}
\begin{document}
    
    \chemfig{*6(--*6(--*6(-----)---)----)}
    
    \hspace{1cm}
    
    \chemfig{*6(-*6(-*6(-----)----)-----)}
    
    \hspace{1cm}
    
        \chemfig{*6(-*6(----*6(----)-)-----)}
\end{document}

enter image description here

4

Just for fun a different input syntax.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\tikzset{
  hexa setup/.style 2 args={
    x=(#2:.86602540378*#1), y=(60+#2:.86602540378*#1),
    hexa node/.style={
      shape=regular polygon, regular polygon sides=6, draw,
      rotate=30+#2,  minimum size=#1, inner sep=+0pt},
    Hexa/.style={/tikz/insert path={node[hexa node,##1]{}}}},
  hexa/.code=\pgfqkeys{/tikz/hexa}{#1},
  hexa={
    h/.style={/tikz/Hexa},0/.style={/tikz/Hexa},
    /utils/temp/.style args={#1/#2/#3}{#1/.style={
      /tikz/insert path={-- ++(#2,#3)},/tikz/Hexa}},
    /utils/temp/.list={1/1/0, 2/0/1, 3/-1/1, 4/-1/0, 5/0/-1, 6/1/-1}}}
\begin{document}
\begin{tikzpicture}[hexa setup={1cm}{0}]
  \draw[help lines] foreach \dir in {1,...,6}{(0,0) [hexa/\dir] node{\dir}};
  \draw[inner sep=0pt, <->] (0,1) -- (0,0) -- (1,0);
\end{tikzpicture}

\tikz[hexa setup={1cm}{30}]\path[hexa={h,5,5}];
\tikz[hexa setup={1cm}{45}]\path[hexa={h,1,2}];
\tikz[hexa setup={1cm}{ 0}]\path[hexa={h,1,3}];
\end{document}

Output

enter image description here enter image description here enter image description here enter image description here

3

Here is a possibility using chains.

enter image description here

To make a chain, start with \begin{tikzpicture}[hexchain]. If you want the hexagons to have a vertex at the top (as opposed to a side) use hexchain=30. You may use any angle you wish.

Then use \node[myhex, <tikz options>]{<label>} to begin the chain. The label and any additional tikz options are optional. Subsequent nodes should be placed using \node[myhex=<angle>, <tikz options>]{<label>};, where <angle> is the direction from the previous node.

The size of the hexagons is controlled globally by \circdiam.

Here is the code that produces the image:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{chains, shapes.geometric}

\tikzset{hexchain/.style={start chain, node distance=-\pgflinewidth, shape border rotate=#1},
    hexchain/.default={0},
    myhex/.style={regular polygon, regular polygon sides=6, draw, minimum size=\circdiam cm, 
        on chain=going {at=(\tikzchainprevious),shift=(#1:{\circdiam*sqrt(3)/4})}},
    myhex/.default={}}
    
\newcommand{\circdiam}{1} % diameter of circumcircle in cm

\begin{document}

\begin{tikzpicture}[hexchain]
\node[myhex]{1};
\node[myhex=-90]{2};
\node[myhex=-30]{3};
\node[myhex=210]{4};
\end{tikzpicture}\qquad
%
\begin{tikzpicture}[hexchain=30]
\node[myhex, fill=blue!30]{};
\node[myhex=-60, fill=red!30]{};
\node[myhex=-120, fill=yellow!30]{};
\node[myhex=0, fill=green!30]{};
\end{tikzpicture}

\end{document}
3

A MetaPost solution.

First, define a hexagon shape:

path unithex; unithex = up
    -- up rotated  60 -- up rotated 120 -- down
    -- up rotated 240 -- up rotated 300 -- cycle;

Then, a hexshifted macro for using trapezoidal coordinates:

primarydef h hexshifted p = h shifted (p transformed tohex) enddef;
transform tohex; tohex = identity
    slanted 1/2 yscaled 3/2 xscaled sqrt(3);

After which stitching together hexagons becomes rather easy:

beginfig(0)
    draw unithex scaled 1cm;
    draw unithex hexshifted (0,1) scaled 1cm;
    draw unithex hexshifted (1,0) scaled 1cm;
endfig;

three hexagons in a triangular shape

beginfig(1)
    draw unithex scaled 1cm;
    draw unithex hexshifted ( 0,1) scaled 1cm;
    draw unithex hexshifted (-1,2) scaled 1cm;
endfig;

bye

three hexagons stacked above each other

2

Got an idea from this answer:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
\begin{scope}[%
every node/.style={anchor=west,
    regular polygon, 
    regular polygon sides=6,
    draw,
    minimum width=2cm,
    outer sep=0,
    }, transform shape]
    \node (A) {A};
    \node (B) at (A.corner 1) {};
    \node (C) at (B.corner 5) {};
    \node (D) at (A.corner 5) {};
    \node (E) at (D.corner 5) {};
    \node (F) at (A.side 2)[yshift=-150pt]{};
    \node (G) at (F.corner 3)[yshift=-50pt]{};
    \node (H) at (G.corner 3)[yshift=-50pt]{};
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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