# Shifted hexagons in TikZ picture

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:

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

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}


-
+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