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.

With help from answers to TikZ: Drawing regular hexagons with pictures inside, I've created some tiles for a children's game:

enter image description here

To save on costs of printing + card, I'd like to fit 3 more hexes into the gaps in the [a4] paper.

The code that generated that looked like this:

\tile{Lake}{lake.jpg}{1.2}{Starts on Board}{--}{\food}\hfill
\tile{Forest}{forest.jpg}{1.6}{Starts on Board}{--}{\wood}\\

\tile{Forest}{forest.jpg}{1.6}{Starts on Board}{--}{\wood}\hfill
\tile{Forest}{forest.jpg}{1.6}{Starts on Board}{--}{\wood}\\

\tile{Baker}{baker.jpg}{7}{Build on Clearing}{\wood\wood\person}{\convert{\grain}{\food}}\hfill
\tile{Butcher}{butcher.jpg}{10}{Build on Clearing}{\wood\wood\person}{\convert{\sheep}{\food}}\\

\tile{Baker}{baker.jpg}{7}{Build on Clearing}{\wood\wood\person}{\convert{\grain}{\food}}\hfill
\tile{Butcher}{butcher.jpg}{10}{Build on Clearing}{\wood\wood\person}{\convert{\sheep}{\food}}\\

I could add an extra 'location' argument to \tile and cyclically instantiate it with 11 positions, but that would be a pain to maintain when I changed the number of tiles (e.g. changed 3 forests to 4 forests). So: how can I keep the positional information separate from the specification of the contents of the tiles?

Edit: full code as requested. (Tiles have changed a bit, but not in a way that affects the question.)

\documentclass[a4paper]{article}
\usepackage[margin=2mm]{geometry}
\usepackage{tikz,nopageno}
\usepackage{wasysym}

\usetikzlibrary{fit,backgrounds}

\setlength{\parskip}{0mm}

\newcommand{\highlight}[2]{%
\begin{tikzpicture}[baseline = (text.base)]
  \node[inner sep=0pt] (text) {#2};
  \begin{pgfinterruptboundingbox}
    \begin{pgfonlayer}{background}
    \node[fit=(text), rounded corners, fill=white, opacity=#1, draw=none] {};
    \end{pgfonlayer}
  \end{pgfinterruptboundingbox}
\end{tikzpicture}%
}

% General macro to draw a shape filled with a bitmap
\newcommand\fillshape[3]{ % #1 = shape, #2 = filename of texture, #3 = includegraphics options
    \begin{scope}
        \clip #1;
        \node {\includegraphics[#3]{#2}};
    \end{scope}
    \draw[line width=0.5mm] #1;
}

% Particularization for hexagonal shape
\newcommand\fillhexagon[2][]{% #1 (optional) = includegraphics options, #2 = filename of texture
    \fillshape{(0:4) -- (60:4) -- (120:4) -- (180:4) -- (240:4) -- (300:4) -- cycle}{#2}{#1}
}

\newcommand\tile[6]{
\begin{tikzpicture}
    \fillhexagon[scale=#3]{#2};
    \node at (0,2.4) {\highlight{0.65}{\LARGE\bf #1}};    
    \node at (0,0.7) {\highlight{1}{#6}};   
    \draw [rounded corners, fill=white, opacity=1] (-2,-0.6)--(2,-0.6)--(2,-2.5)--(-2,-2.5)--cycle; 
    \node at (0,-1.05) {#4};       
    \node at (0,-1.85) {#5};       
\end{tikzpicture}
}

\newcommand\image[2]{$\vcenter{\hbox{\includegraphics[scale=#1]{#2}}}$}

\newcommand\wood{\image{0.22}{wood.png}}
\newcommand\food{\image{0.23}{bowl.jpg}}
\newcommand\person{\image{0.25}{peasant.jpg}}
\newcommand\grain{\image{0.5}{grain2.jpg}}
\newcommand\sheep{\image{0.05}{sheep.png}}
\newcommand\stone{\image{0.35}{stone.png}}
\newcommand\ale{\image{0.12}{ale.png}}
%\newcommand\cloth{\image{0.2}{cloth.png}}
\newcommand\paper{\image{0.1}{paper.png}}
\newcommand\gold{\image{0.7}{gold.jpg}}
\newcommand\marble{\image{0.2}{marble.jpg}}

\newcommand\TO{\Huge$\rightarrow$}

\newcommand*{\vpointer}{$\vcenter{\hbox{\ \scalebox{2}{$\rightarrow$}}}$}

\newcommand\convert[2]{#1\vpointer\, #2}

\begin{document}
\tile{Lake}{lake.jpg}{1.2}{Starts on Board}{--}{\food}\hfill
\tile{Field}{field2.jpg}{1.5}{Replaces Clearing}{\person\person\person\person}{\grain}\\

\tile{Forest}{forest2.jpg}{0.4}{Starts on Board}{--}{\wood}\hfill
\tile{Mountain}{mountain2.jpg}{0.3}{Starts on Board}{--}{--}\\

\tile{Baker}{baker.jpg}{7}{Build on Clearing}{\wood\wood\person}{\convert{\grain}{\food}}\hfill
\tile{Butcher}{butcher.jpg}{10}{Build on Clearing}{\wood\wood\person}{\convert{\sheep}{\food}}\\

\tile{Grazing}{grazing.jpg}{0.3}{Replaces Hill}{\person}{\sheep}\hfill
\tile{Pasture}{sheepfield.jpg}{2.1}{Replaces Clearing}{\wood\sheep\sheep\sheep\sheep}{\sheep\sheep}

\end{document}
share|improve this question
1  
Can you add the full code starting from \documentclass{...} and ending at \end{document}? –  Harish Kumar Jan 23 at 23:18
    
@Harish Kumar: Done. –  Mohan Jan 23 at 23:39
    
Thanks. Is putting \tiles in a table valid for you? –  Harish Kumar Jan 23 at 23:46
    
How are you going to cut out the pieces? If laser cut, that's ok. If by hand, I would keep some continuous straight lines, even if that meant blank spaces. If you're going to print at a shop, they usually have larger formats than A4 and those are usually a better value. At least where I live. (I would have commented instead of answered, but I couldn't, sorry.) Edit for clarity: Hexagons allow uniform tiling, that is, they fit without gaps. en.wikipedia.org/wiki/File:Uniform_tiling_63-t0.png. But then cut lines run through the center of the next hexagon. So you want a layout with gaps, l –  olga.saucedo Jan 23 at 23:54
    
@Harish Kumar: certainly, so long as I can insert/delete rows easily. –  Mohan Jan 24 at 0:10

2 Answers 2

Your hexagons are bit wider to fit 3 of them on a line. Hence I introduced \mylength to adjust. You can use a tabular to arrange the tiles with a column definition:

\newcolumntype{C}{>{\centering\arraybackslash}p{\dimexpr0.32\textwidth-2\tabcolsep\relax}}

using array package and use them like

\begin{tabular}{CCC}

Code:

\PassOptionsToPackage{draft}{graphicx}   %% uncomment in your system
\documentclass{article}
\usepackage[a4paper,margin=2mm]{geometry}
\usepackage{tikz,nopageno}
\usepackage{wasysym}
\usepackage{array}
\newcolumntype{C}{>{\centering\arraybackslash}p{\dimexpr0.32\textwidth-2\tabcolsep\relax}}

\usetikzlibrary{fit,backgrounds}

\setlength{\parskip}{0mm}
\newlength{\mywidth}
\setlength{\mywidth}{3cm}  %%% size of the hexagon adjusted so that three hexgons fit

\newcommand{\highlight}[2]{%
\begin{tikzpicture}[baseline = (text.base)]
  \node[inner sep=0pt] (text) {#2};
  \begin{pgfinterruptboundingbox}
    \begin{pgfonlayer}{background}
    \node[fit=(text), rounded corners, fill=white, opacity=#1, draw=none] {};
    \end{pgfonlayer}
  \end{pgfinterruptboundingbox}
\end{tikzpicture}%
}

% General macro to draw a shape filled with a bitmap
\newcommand\fillshape[3]{% #1 = shape, #2 = filename of texture, #3 = includegraphics options
    \begin{scope}
        \clip #1;
        \node {\includegraphics[#3]{#2}};
    \end{scope}
    \draw[line width=0.5mm] #1;
}%

% Particularization for hexagonal shape
\newcommand\fillhexagon[2][]{% #1 (optional) = includegraphics options, #2 = filename of texture
    \fillshape{(0:\mywidth) -- (60:\mywidth) -- (120:\mywidth) -- (180:\mywidth) -- (240:\mywidth) -- (300:\mywidth) -- cycle}{#2}{#1}
}

\newcommand\tile[6]{
\begin{tikzpicture}
    \fillhexagon[scale=#3]{#2};
    \node at (0,2.4) {\highlight{0.65}{\LARGE\bf #1}};
    \node at (0,0.7) {\highlight{1}{#6}};
    \draw [rounded corners, fill=white, opacity=1] (-2,-0.6)--(2,-0.6)--(2,-2.5)--(-2,-2.5)--cycle;
    \node at (0,-1.05) {#4};
    \node at (0,-1.85) {#5};
\end{tikzpicture}
}

\newcommand\image[2]{$\vcenter{\hbox{\includegraphics[scale=#1]{#2}}}$}

\newcommand\wood{\image{0.22}{wood.png}}
\newcommand\food{\image{0.23}{bowl.jpg}}
\newcommand\person{\image{0.25}{peasant.jpg}}
\newcommand\grain{\image{0.5}{grain2.jpg}}
\newcommand\sheep{\image{0.05}{sheep.png}}
\newcommand\stone{\image{0.35}{stone.png}}
\newcommand\ale{\image{0.12}{ale.png}}
%\newcommand\cloth{\image{0.2}{cloth.png}}
\newcommand\paper{\image{0.1}{paper.png}}
\newcommand\gold{\image{0.7}{gold.jpg}}
\newcommand\marble{\image{0.2}{marble.jpg}}

\newcommand\TO{\Huge$\rightarrow$}

\newcommand*{\vpointer}{$\vcenter{\hbox{\ \scalebox{2}{$\rightarrow$}}}$}

\newcommand\convert[2]{#1\vpointer\, #2}

\begin{document}
\begin{tabular}{CCC}
\tile{Lake}{lake.jpg}{1.2}{Starts on Board}{--}{\food}&
\tile{Field}{field2.jpg}{1.5}{Replaces Clearing}{\person\person\person\person}{\grain}&
\tile{Forest}{forest2.jpg}{0.4}{Starts on Board}{--}{\wood}\\%%[1ex] %% uncomment to adjust vertical gap

\tile{Mountain}{mountain2.jpg}{0.3}{Starts on Board}{--}{--}&
\tile{Baker}{baker.jpg}{7}{Build on Clearing}{\wood\wood\person}{\convert{\grain}{\food}}&
\tile{Butcher}{butcher.jpg}{10}{Build on Clearing}{\wood\wood\person}{\convert{\sheep}{\food}}\\%%[1ex] %% uncomment to adjust vertical gap

\tile{Grazing}{grazing.jpg}{0.3}{Replaces Hill}{\person}{\sheep}&
\tile{Pasture}{sheepfield.jpg}{2.1}{Replaces Clearing}{\wood\sheep\sheep\sheep\sheep}{\sheep\sheep}&
\end{tabular}

\end{document}

enter image description here

You can adjust the vertical gap between rows so as to suit your needs. Sorry for the bad picture but I don't have patience to find a replacement for all those images.

Tiled version with tabular

\PassOptionsToPackage{draft}{graphicx}
\documentclass[a4paper]{article}
\usepackage[margin=2mm]{geometry}
\usepackage{tikz,nopageno}
\usepackage{wasysym}
\usepackage{array}
\newcolumntype{C}{>{\centering\arraybackslash}p{\dimexpr0.23\textwidth-2\tabcolsep\relax}}

\usetikzlibrary{fit,backgrounds}

\setlength{\parskip}{0mm}
\newlength{\mywidth}
\setlength{\mywidth}{3.7cm}  %%% size of the hexagon adjusted so that three hexgons fit

\newcommand{\highlight}[2]{%
\begin{tikzpicture}[baseline = (text.base)]
  \node[inner sep=0pt] (text) {#2};
  \begin{pgfinterruptboundingbox}
    \begin{pgfonlayer}{background}
    \node[fit=(text), rounded corners, fill=white, opacity=#1, draw=none] {};
    \end{pgfonlayer}
  \end{pgfinterruptboundingbox}
\end{tikzpicture}%
}

% General macro to draw a shape filled with a bitmap
\newcommand\fillshape[3]{% #1 = shape, #2 = filename of texture, #3 = includegraphics options
    \begin{scope}
        \clip #1;
        \node {\includegraphics[#3]{#2}};
    \end{scope}
    \draw[line width=0.5mm] #1;
}%

% Particularization for hexagonal shape
\newcommand\fillhexagon[2][]{% #1 (optional) = includegraphics options, #2 = filename of texture
    \fillshape{(0:\mywidth) -- (60:\mywidth) -- (120:\mywidth) -- (180:\mywidth) -- (240:\mywidth) -- (300:\mywidth) -- cycle}{#2}{#1}
}

\newcommand\tile[6]{
\begin{tikzpicture}
    \fillhexagon[scale=#3]{#2};
    \node at (0,2.4) {\highlight{0.65}{\LARGE\bf #1}};
    \node at (0,0.7) {\highlight{1}{#6}};
    \draw [rounded corners, fill=white, opacity=1] (-2,-0.6)--(2,-0.6)--(2,-2.5)--(-2,-2.5)--cycle;
    \node at (0,-1.05) {#4};
    \node at (0,-1.85) {#5};
\end{tikzpicture}
}

\newcommand\image[2]{$\vcenter{\hbox{\includegraphics[scale=#1]{#2}}}$}

\newcommand\wood{\image{0.22}{wood.png}}
\newcommand\food{\image{0.23}{bowl.jpg}}
\newcommand\person{\image{0.25}{peasant.jpg}}
\newcommand\grain{\image{0.5}{grain2.jpg}}
\newcommand\sheep{\image{0.05}{sheep.png}}
\newcommand\stone{\image{0.35}{stone.png}}
\newcommand\ale{\image{0.12}{ale.png}}
%\newcommand\cloth{\image{0.2}{cloth.png}}
\newcommand\paper{\image{0.1}{paper.png}}
\newcommand\gold{\image{0.7}{gold.jpg}}
\newcommand\marble{\image{0.2}{marble.jpg}}

\newcommand\TO{\Huge$\rightarrow$}

\newcommand*{\vpointer}{$\vcenter{\hbox{\ \scalebox{2}{$\rightarrow$}}}$}

\newcommand\convert[2]{#1\vpointer\, #2}

\begin{document}

\begin{tabular}{cCc}
\tile{Lake}{lake.jpg}{1.2}{Starts on Board}{--}{\food}&
&
\tile{Forest}{forest2.jpg}{0.4}{Starts on Board}{--}{\wood}\\[-3cm] %% uncomment to adjust vertical gap

&
\makebox[0pt][c]{\tile{Baker}{baker.jpg}{7}{Build on Clearing}{\wood\wood\person}{\convert{\grain}{\food}}}&
\\[-3cm] %% uncomment to adjust vertical gap

\tile{Lake}{lake.jpg}{1.2}{Starts on Board}{--}{\food}&
&
\tile{Forest}{forest2.jpg}{0.4}{Starts on Board}{--}{\wood}\\[-3cm] %% uncomment to adjust vertical gap

&
\makebox[0pt][c]{\tile{Baker}{baker.jpg}{7}{Build on Clearing}{\wood\wood\person}{\convert{\grain}{\food}}}&
\\[-3cm] %% uncomment to adjust vertical gap

\tile{Lake}{lake.jpg}{1.2}{Starts on Board}{--}{\food}&
&
\tile{Forest}{forest2.jpg}{0.4}{Starts on Board}{--}{\wood}\\[-3cm] %% uncomment to adjust vertical gap

&
\makebox[0pt][c]{\tile{Baker}{baker.jpg}{7}{Build on Clearing}{\wood\wood\person}{\convert{\grain}{\food}}}&
\\[-3cm] %% uncomment to adjust vertical gap

\tile{Lake}{lake.jpg}{1.2}{Starts on Board}{--}{\food}&
&
\tile{Forest}{forest2.jpg}{0.4}{Starts on Board}{--}{\wood}\\[-3cm] %% uncomment to adjust vertical gap

%&
%\makebox[0pt][c]{\tile{Baker}{baker.jpg}{7}{Build on Clearing}{\wood\wood\person}{\convert{\grain}{\food}}}&
%\\[-3cm] %% uncomment to adjust vertical gap

\end{tabular}
\end{document}

enter image description here

This may make cutting difficult, but I hope adding/deleting rows shouldn't be difficult.

share|improve this answer

How about defining a coordinate system? Then you can use what ever tikz method you choose to create the tiles and then just shift the transformation matrix using the coordinate system.

Some apologies for the slightly boring tile content. To space the tiles out more just set the x and and y vectors to larger values.

\documentclass[tikz,border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\tikzset{hexagon/.style args={#1with image#2[#3]#4(#5)}{%
  regular polygon, regular polygon sides=6, 
  path picture={\node{\includegraphics[#3]{#5}};},
  draw, ultra thick, minimum size=#1, node contents=},
  %
  hexagonal cs/.cd,
    x/.store in=\hexx, y/.store in=\hexy,
    x=0,y=0, 
}
\tikzdeclarecoordinatesystem{hexagonal}{%
  \tikzset{hexagonal cs/.cd,#1}%
  \pgfpointxy{\hexx*0.75}{(\hexy-mod(\hexx,2)/2)*cos(30)}%
}
\begin{document}
\begin{tikzpicture}
\foreach \h [evaluate={\i=mod(\h,5); \j=floor(\h/5);
  \k=random(0,2); \l={"a","b","c"}[\k];}] in {0,...,24}
  \node [x=2.25cm, y=2.25cm] at (hexagonal cs:x=\j, y=\i) 
    [hexagon={2cm with image [scale=0.25] (example-image-\l)}];
\end{tikzpicture}
\end{document}

enter image description here

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.