2

I want to create the net of a flattened hexagonal based box. Each side of the box is a slight trapezium (so in 3D the sides will not be perpendicular to the base, but that's not important to the question). Since each side is the same but only positioned differently I tried the following MWE.

\documentclass{article}
\usepackage{tikz}    
\begin{document}

\newcommand{\side}[1][10]{%
\begin{tikzpicture}
\coordinate (sO) at (0,0);
\path (sO)--++(-90:2) coordinate (sB);
\path (sO)--++({#1}:1) coordinate (sC);
\path (sB)--++({-1*#1}:1) coordinate (sD);
\draw (sO)--(sB)--(sD)--(sC)--(sO);
\end{tikzpicture}%
}


\begin{tikzpicture}
\coordinate (O) at (0,0);
\path (O)--++(0:2)  coordinate (A1);
\path (O)--++(60:2) coordinate (A2);
\path (O)--++(120:2) coordinate (A3);
\path (O)--++(180:2) coordinate (A4);
\path (O)--++(240:2) coordinate (A5);
\path (O)--++(300:2) coordinate (A6);

\draw (A1)
--node[sloped,rotate=90,anchor=west]{\side}(A2)
--node[sloped,rotate=90,anchor=west]{\side}(A3)
--node[sloped,rotate=90,anchor=west]{\side}(A4)
--node[sloped,rotate=-90,anchor=west]{\side}(A5)
--node[sloped,rotate=-90,anchor=west]{\side}(A6)
--node[sloped,rotate=-90,anchor=west]{\side}(A1);

\end{tikzpicture}

\end{document}

The sides are not flush on the sides of the hexagon. Is there a way to do this elegantly?

Or perhaps my code could be improved, in particular to have the same node information (sometimes I needed rotate=90, other times rotate=-90).

enter image description here

  • If someone could include a picture, I'd be grateful. – Geoff Jan 28 '14 at 10:47
  • This TeXample by Till Tantau should be of interest: texample.net/tikz/examples/foldable-dodecahedron-with-calendar – jub0bs Jan 28 '14 at 11:03
  • Try to add inner sep=0pt in node[sloped,... Is this what you want? – Ignasi Jan 28 '14 at 11:03
  • The folding library only seems to have one predetermined shape. It would be nice to see how the repeated shapes are easily positioned. The inner sep though solved that space problem. – Geoff Jan 28 '14 at 11:22
  • @Ignasi Your comment of the inner sep=0pt solves the problem of the spaces. If you state this as an answer I will accept. Concerning the elegance of the code, repeating blocks and repositioning them, I posted a follow on question. Many thanks. – Geoff Jan 28 '14 at 17:22
1

You need to fix inner sep=0pt (or even better -\pgflinewidth) for your \side nodes. Next code shows both options. You can also see why your trapezium are not join to hexagon. Every node has a (by default not zero) inner sep between its contents and node border.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}    
\begin{document}

\newcommand{\side}[1][10]{%
\begin{tikzpicture}
\coordinate (sO) at (0,0);
\path (sO)--++(-90:2) coordinate (sB);
\path (sO)--++({#1}:1) coordinate (sC);
\path (sB)--++({-1*#1}:1) coordinate (sD);
\draw (sO)--(sB)--(sD)--(sC)--(sO);
\end{tikzpicture}%
}


\begin{tikzpicture}
\coordinate (O) at (0,0);
\path (O)--++(0:2)  coordinate (A1);
\path (O)--++(60:2) coordinate (A2);
\path (O)--++(120:2) coordinate (A3);
\path (O)--++(180:2) coordinate (A4);
\path (O)--++(240:2) coordinate (A5);
\path (O)--++(300:2) coordinate (A6);

\draw (A1)
--node[sloped,rotate=90,anchor=west, inner sep=-\pgflinewidth]{\side}(A2)
--node[sloped,rotate=90,anchor=west, inner sep=-\pgflinewidth]{\side}(A3)
--node[sloped,rotate=90,anchor=west, inner sep=0pt]{\side}(A4)
--node[sloped,rotate=-90,anchor=west, inner sep=-\pgflinewidth]{\side}(A5)
--node[sloped,rotate=-90,anchor=west, inner sep=0pt]{\side}(A6)
--node[sloped,rotate=-90,anchor=west, draw=red]{\side}(A1);

\end{tikzpicture}

\end{document}

enter image description here

|improve this answer|||||

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.