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.

Recently there was a great answer in How to draw a 3D hexagonal structure with TikZ?

But I noticed a small "bug" which I can't seem to be able to fix. I stripped the code down that shows the problem:

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

\begin{document}
\begin{tikzpicture}
  \begin{scope}[%
      every node/.style={anchor=west,regular polygon, regular polygon sides=6,draw,inner sep=0.5cm},
      transform shape]
    \node (A) {A};
    \node (B) at (A.corner 1) {B};
    \node (C) at (B.corner 5) {C};
    \node (D) at (A.corner 5) {D};
    \node (E) at (D.corner 5) {E};
    \foreach \hex in {A,...,E}
    {
      \foreach \corn in {1,...,6}
        \draw[fill=white] (\hex.corner \corn) circle (2pt); 
    }
  \end{scope}
\end{tikzpicture}
\end{document}

This code draws five nodes with hexagonal shape, but the hexagons are a few, but always a different "number of few", pixels "off", as shown in this picture:

enter image description here

  • Which value is responsible for this?
  • Why is the "shifting" happening with different strength?
  • How to fix it?
share|improve this question
3  
+1 for: "I stripped the code down that shows the problem:" –  kan Apr 12 '13 at 13:27

1 Answer 1

up vote 14 down vote accepted

You would need outer sep=0 and also inner sep is dependent on the node contents and the node size change accordingly. Instead you can use minimum height/width keys.

\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) {B};
    \node (C) at (B.corner 5) {C};
    \node (D) at (A.corner 5) {DECF};
    \node (E) at (D.corner 5) {E};
    \foreach \hex in {A,...,E}
    {
      \foreach \corn in {1,...,6}
        \draw[fill=white] (\hex.corner \corn) circle (2pt); 
    }
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
+1 this one was about tikz:-) –  David Carlisle Apr 12 '13 at 13:32
    
Nice, this works as expected. Thank you very much. :) I already noticed that the letters increase the shifting, but also with empty nodes the problem was there. But this is now also fixed thanks to outer sep. :) –  Foo Bar Apr 12 '13 at 13:33

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.