Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to draw an image like the following:

alt text

I did this using the following Tikz code:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepgflibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}
  [hexagon/.style={regular polygon, regular polygon sides=6,
    draw, minimum size=1cm, anchor=center}]

  \foreach \x in {0,...,2}
    \node at (\x, 5) [hexagon]{};
  \foreach \x in {0,...,3}
    \node at (\x-0.5, 4.12) [hexagon]{};
  \foreach \x in {0,...,4}
    \node at (\x-1, 3.25) [hexagon]{};
  \foreach \x in {0,...,3}
    \node at (\x-.5, 2.38) [hexagon]{};
  \foreach \x in {0,...,2}
    \node at (\x, 1.52) [hexagon]{};

\end{tikzpicture}
\end{document}

Is there a better way to code this, using fewer manually-calculated approximations in Tikz? Also, as can be seen, the lines overlap in a weird inexact way. Can I avoid that too?

share|improve this question
1  
This is very similar to this question, the answers to which you can modify to your liking –  Yossi Farjoun Dec 15 '10 at 8:22

1 Answer 1

up vote 12 down vote accepted

I realized that this question is slightly different form the drawing hexagons of yore...so, how about this solution:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepgflibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}
  [hexagon/.style={regular polygon, regular polygon sides=6,
    draw, minimum size=1cm, anchor=center}]
  \foreach[evaluate=\y] \y in {-2,...,2}
  {
  \pgfmathparse{5-abs{ \y }}
\foreach \x in {1,...,\pgfmathresult}
\node at (abs \y /2 +\x, sqrt 3 * \y/2) [hexagon]{};
}
\end{tikzpicture}
\end{document}

which yields: alt text

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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