3

I want to create a style for a hexagon like this :

enter image description here

But, I don't know how to do it. This is my code for now:

\begin{tikzpicture}[
    ]

    \newdimen\R
    \R=2.7cm
    \draw (0:\R)
    \foreach \x in {60,120,...,360} {  -- (\x:\R) }
        -- cycle (360:\R)  
        -- cycle (300:\R) 
        -- cycle (240:\R) 
        -- cycle (180:\R) 
        -- cycle  (120:\R)
        -- cycle  (60:\R) ;
\end{tikzpicture}

Which only draw a hexagon. Thanks for the help

  • Oky, found a easier way to draw hexagon, but not how to add the labels, and draws the background : \tikz\path node[ regular polygon, regular polygon sides=6, draw, inner sep=1.7cm, ] (hexagon) {} (hexagon); – Warok Jun 26 at 8:36
4

Yet another possible solution.

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,intersections,calc}

\begin{document}
\begin{tikzpicture}[]
\def\rot{-60}    
\node[regular polygon, regular polygon sides=6, shape aspect=0.5, minimum width=4cm, minimum height=1cm, draw,shape border rotate=\rot] (reg) {};

\path [draw,name path=beam1] ($(reg.corner 3)!0.65!(reg.corner 4)$)coordinate(A)--($(reg.corner 5)!0.35!(reg.corner 6)$)coordinate(B);
\begin{scope}[rotate=\rot]
\path [name path=beam2](reg.side 4)--++(90:2);
\path [name intersections={of=beam1 and beam2,by={x}}];
\draw (reg.side 4)--(x);
\filldraw [opacity=0.3,cyan](A)--(B)--(reg.corner 5)--(reg.corner 4)--cycle;
\node[rotate=\rot] at (x)[anchor=north west]{label};
\node[rotate=\rot] at (x)[anchor=north east]{label};
\end{scope}
\end{tikzpicture}

\end{document}

enter image description here

  • Nice, thanks for the help :) – Warok Jun 26 at 11:04
  • @Warok, your welcome. – ferahfeza Jun 26 at 11:05
3

A possible solution:

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}[
    mylabel/.style={rectangle, draw, minimum width=2cm, minimum height=6mm, inner sep=1pt,
        fill=#1},
    mylabel/.default={blue!30}
    ]
\node[regular polygon, regular polygon sides=6, draw, inner sep=1.7cm, 
    path picture={%
        \node[mylabel, anchor=south west] at (path picture bounding box.south) {label};
        \node[mylabel=red!30, anchor=south east] at (path picture bounding box.south) {label};
        }
    ] (hexagon) {};

\end{tikzpicture}
\end{document}

enter image description here

In case you want labels on other sides, this is a not so good solution because path picture bounding box used in previous solution doesn't inherit side and corner anchors. This alternative should reuse hexagon border as clipping path, but I don't know how to do it so I did it with manual path.

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}[
    mylabel/.style={rectangle, draw, minimum width=2cm, minimum height=6mm, inner sep=1pt,
        fill=#1},
    mylabel/.default={blue!30}
    ]
\node[regular polygon, regular polygon sides=6, draw, inner sep=1.7cm, 
    shape border rotate=30] (hexagon) {};

\begin{scope}
\clip (hexagon.side 2)--(hexagon.corner 3)--(hexagon.corner 4)--(hexagon.side 4)--cycle;
\node[mylabel, anchor=south west, rotate=-30] at (hexagon.side 3) {label};
\node[mylabel=red!30, anchor=south east, rotate=-30] at (hexagon.side 3) {label};
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

  • Thanks for the help – Warok Jun 26 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.