This question regards creating a memory game using Tikz.I would like to ask for help with creating a loop that will place memory cards on the page.
There are many standards, I believe, but let us pick one:
- memory game is printed on three pages, consisting of 32x2 square cards
- two pages contain 4x6 cards, the third page contains 16 cards (the image bellow shows the layout)
The question is: How to place the cards in foreach loop, passing several arguments in array(s) of values? The array(s) of arguments will be: the name of the image file, the text, the colour value.
Pseudo foreach loop will look like this:
Place first image in array, place first title in array and use first colour in array; shift position by xshift=71pt, place second ...
After fourth image shift by yshift...
Minor update: Using this loop way it will be easy to create back of the cards passing the same value of image file. On the other hand all needs to be centred.
\documentclass[12pt]{article}
% ############################## geometry
\usepackage{geometry}
\geometry{
headsep = 0pt,
headheight= 0pt,
hmarginratio = 1:1,
vmarginratio = 1:1,
bindingoffset = 0cm,
onecolumn,
a3paper,
layoutwidth = 220 mm,
layoutheight = 320 mm,
layouthoffset=\dimexpr(\paperwidth-\csname Gm@layoutwidth\endcsname)/2\relax,
layoutvoffset=\dimexpr(\paperheight-\csname Gm@layoutheight\endcsname)/2\relax,
showcrop
}
\usepackage[icelandic, latin, czech]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\definecolor{title}{RGB}{16, 13, 32}
\usepackage{mwe}
\usepackage{XCharter}
% ############################### Document
\newcommand{\czHyphen}{\rule[.45ex]{.2em}{.11ex}}
\newcommand*{\addthinS}{\hskip0.06667em\relax}
\newcommand*{\addthinSS}{\hskip0.00007em\relax}
\def\cropmarkgap{1}% mm
\makeatletter
\def\Gm@cropmark(#1,#2,#3,#4){% #1 = x direction, #2 = y direction, #3 & #4 no longet used
\begin{picture}(0,0)
\setlength\unitlength{1truemm}%
\linethickness{0.25pt}%
\put(\the\numexpr #1*\cropmarkgap\relax,0){\line(#1,0){\the\numexpr 20-\cropmarkgap}}%
\put(0,\the\numexpr #2*\cropmarkgap\relax){\line(0,#2){\the\numexpr 20-\cropmarkgap}}%
\end{picture}}%
\makeatother
\makeatletter
\def\parsecomma#1,#2\endparsecomma{\def\page@x{#1}\def\page@y{#2}}
\tikzdeclarecoordinatesystem{page}{
\parsecomma#1\endparsecomma
\pgfpointanchor{current page}{north east}
% Save the upper right corner
\pgf@xc=\pgf@x%
\pgf@yc=\pgf@y%
% save the lower left corner
\pgfpointanchor{current page}{south west}
\pgf@xb=\pgf@x%
\pgf@yb=\pgf@y%
% Transform to the correct placement
\pgfmathparse{(\pgf@xc-\pgf@xb)/2.*\page@x+(\pgf@xc+\pgf@xb)/2.}
\expandafter\pgf@x\expandafter=\pgfmathresult pt
\pgfmathparse{(\pgf@yc-\pgf@yb)/2.*\page@y+(\pgf@yc+\pgf@yb)/2.}
\expandafter\pgf@y\expandafter=\pgfmathresult pt
}
\makeatother
\usepackage{eso-pic}
\usepackage{tikzpagenodes}
%\AddToShipoutPicture{\drawbackground}
\newcommand{\shiftleft}{\hspace*{-0.55\dimexpr\csname Gm@layoutwidth\endcsname-\textwidth\relax}}
\newcommand{\shiftup}{\vspace*{-0.13\dimexpr\csname Gm@layoutheight\endcsname-\textwidth\relax}}
\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[remember picture, overlay]
\tikzset{p_title/.style={text centered, minimum height=0.6cm, minimum width=5cm, font=\bfseries}}
\tikzset{p_title_line/.style={ultra thin, color=violet}}
\node[inner sep=0pt] (A) at (page cs:-0.5045,0.595)
{\includegraphics[width=5cm]{example-image}};
\draw[black, ultra thick] ($(A.north west)$) rectangle ($(A.south east)$);
\node [p_title] (AA) at ($(A.north west)+(2.5,-0.30)$) {{title text}};
\draw [p_title_line](AA.south west) -- (AA.south east);
\node[inner sep=0pt] (B) at ([xshift=71pt]A.east)
{\includegraphics[width=5cm]{example-image}};
\draw[black, ultra thick] ($(B.north west)$) rectangle ($(B.south east)$);
\node [p_title] (BB) at ($(B.north west)+(2.5,-0.30)$) {{amma}};
\draw [p_title_line](BB.south west) -- (BB.south east);
\node[inner sep=0pt] (C) at ([xshift=71pt]B.east)
{\includegraphics[width=5cm]{example-image}};
\draw[black, ultra thick] ($(C.north west)$) rectangle ($(C.south east)$);
\node [p_title] (CC) at ($(C.north west)+(2.5,-0.30)$) {{banka}};
\draw [p_title_line](CC.south west) -- (CC.south east);
\node[inner sep=0pt] (D) at ([xshift=71pt]C.east)
{\includegraphics[width=5cm]{example-image}};
\draw[black, ultra thick] ($(D.north west)$) rectangle ($(D.south east)$);
\node [p_title] (DD) at ($(D.north west)+(2.5,-0.30)$) {{strætó}};
\draw [p_title_line](DD.south west) -- (DD.south east);
% second line
\node[inner sep=0pt] (E) at ([yshift=-71pt]A.south)
{\includegraphics[width=5cm]{example-image}};
\draw[black, ultra thick] ($(E.north west)$) rectangle ($(E.south east)$);
\node [p_title] (EE) at ($(E.north west)+(2.5,-0.30)$) {{bíll}};
\draw [p_title_line](EE.south west) -- (EE.south east);
\node[inner sep=0pt] (F) at ([xshift=71pt]E.east)
{\includegraphics[width=5cm]{example-image}};
\draw[black, ultra thick] ($(F.north west)$) rectangle ($(F.south east)$);
\node [p_title] (FF) at ($(F.north west)+(2.5,-0.30)$) {{strætó}};
\draw [p_title_line](FF.south west) -- (FF.south east);
\node[inner sep=0pt] (G) at ([xshift=71pt]F.east)
{\includegraphics[width=5cm]{example-image}};
\draw[black, ultra thick] ($(G.north west)$) rectangle ($(G.south east)$);
\node [p_title] (GG) at ($(G.north west)+(2.5,-0.30)$) {{banka}};
\draw [p_title_line](GG.south west) -- (GG.south east);
\node[inner sep=0pt] (H) at ([xshift=71pt]G.east)
{\includegraphics[width=5cm]{example-image}};
\draw[black, ultra thick] ($(H.north west)$) rectangle ($(H.south east)$);
\node [p_title] (HH) at ($(H.north west)+(2.5,-0.30)$) {{autobus}};
\draw [p_title_line](HH.south west) -- (HH.south east);
%third line
\end{tikzpicture}
\clearpage
\end{document}



tcbrasterfromtcolorbox. It easily produces distribution of boxes like yours and it's possible to use aforeachloop inside it. Some examples http://tex.stackexchange.com/a/251710/1952, http://tex.stackexchange.com/a/214787/1952. – Ignasi Feb 19 '16 at 08:22tcbrastercan I position and align text over the image? I seems to me that I need image (with text and line) already ready as a whole. Is that right? – chejnik Feb 19 '16 at 09:35