A table with square cells
\documentclass[border=20pt]{standalone}
\usepackage[thinlines]{easytable}
\begin{document}
\huge
\begin{TAB}(e,2cm,2cm){|c:c:c:c:c|}{|c:c:c:c:c|}
1 & 2 & 3 & 4 & 5 \\
6 & 7 & & & \\
& & & & \\
& & & & \\
& & & &
\end{TAB}
\end{document}
Randomly Generating the Nodes:
Here is a version that randomly generated the nodes using that random number generator built into pgf
using the algorithm:
- Column
B
contains numbers 1 - 15 - Column
I
contains numbers 16 - 30 - Column
N
contains numbers 31 - 45 - Column
G
contains numbers 46 - 60 - Column
O
contains numbers 61 - 75
Further Enhancements:
- Not sure if duplicated numbers are allowed in a column, if not then this can be enhanced to loop if a previously used number is generated
- Add a fancy border and label the columns:
B
,I
,N
,G
,O
Code:
\documentclass{article}
\usepackage{xstring}
\usepackage{tikz}
\usetikzlibrary{calc}
% Column B contains numbers 1 - 15
% Column I contains numbers 16 - 30
% Column N contains numbers 31 - 45
% Column G contains numbers 46 - 60
% Column O contains numbers 61 - 75
\def\NumOfColumns{5}%
\def\Sequence{1/A/1/15, 2/B/16/30, 3/C/31/45, 4/D/46/60, 5/E/61/71}%
\newcommand{\Size}{2.5cm}
\tikzset{Square/.style={
inner sep=0pt,
text width=\Size,
minimum size=\Size,
draw=black,
fill=yellow!20,
align=center,
}
}
\begin{document}
\begin{tikzpicture}[draw=black, ultra thick, x=\Size,y=\Size]
\foreach \row/\rowLetter/\MinNumber/\MaxNumber in \Sequence{%
\foreach \col/\colLetter/\MinNumber/\MaxNumber in \Sequence {%
\pgfmathtruncatemacro{\value}{\col+\NumOfColumns*(\row-1)}
\def\NodeText{\pgfmathparse{random(\MinNumber,\MaxNumber)}\pgfmathresult}
\pgfmathsetmacro{\ColRowProduce}{\col*\row}
\IfEq{\ColRowProduce}{9}{% If is center square
\node [Square] at ($(\col,-\row)-(0.5,0.5)$) {\Huge Free Space};
}{
\node [Square] at ($(\col,-\row)-(0.5,0.5)$) {\Huge \NodeText};
}
}
}
\end{tikzpicture}
\end{document}
Manually Specifying the Nodes:
I am not sure how you want to set the contents of each cell to be specified, so I provided individual \Node<col><row>
macros that you can fill in. If there is an algorithm for choosing those then that too can be automated.
The following uses TikZ nodes. You can change the setting of \Size
to specify the length of the side of the square.
Code:
\documentclass{article}
\usepackage{xstring}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\Size}{2.5cm}% Adjust size of square as desired
\def\NumOfColumns{5}%
\def\Sequence{1/A, 2/B, 3/C, 4/D, 5/E}% This needs to match \NumOfColumns
\tikzset{Square/.style={
inner sep=0pt,
text width=\Size,
minimum size=\Size,
draw=black,
fill=yellow!20,
align=center
}
}
% Define the contents of the cells here.
\newcommand{\NodeAA}{Node $(1,1)$}%
\newcommand{\NodeAB}{Node $(1,2)$}%
\newcommand{\NodeAC}{Node $(1,3)$}%
\newcommand{\NodeAD}{Node $(1,4)$}%
\newcommand{\NodeAE}{Node $(1,5)$}%
\newcommand{\NodeBA}{Node $(2,1)$}%
\newcommand{\NodeBB}{Node $(2,2)$}%
\newcommand{\NodeBC}{Node $(2,3)$}%
\newcommand{\NodeBD}{Node $(2,4)$}%
\newcommand{\NodeBE}{Node $(2,5)$}%
\newcommand{\NodeCA}{Node $(3,1)$}%
\newcommand{\NodeCB}{Node $(3,2)$}%
\newcommand{\NodeCC}{Node $(3,3)$}%
\newcommand{\NodeCD}{Node $(3,4)$}%
\newcommand{\NodeCE}{Node $(3,5)$}%
\newcommand{\NodeDA}{Node $(4,1)$}%
\newcommand{\NodeDB}{Node $(5,2)$}%
\newcommand{\NodeDC}{Node $(5,3)$}%
\newcommand{\NodeDD}{Node $(5,4)$}%
\newcommand{\NodeDE}{Node $(5,5)$}%
\newcommand{\NodeEA}{Node $(5,1)$}%
\newcommand{\NodeEB}{Node $(5,2)$}%
\newcommand{\NodeEC}{Node $(5,3)$}%
\newcommand{\NodeED}{Node $(5,4)$}%
\newcommand{\NodeEE}{Node $(5,5)$}%
\begin{document}
\begin{tikzpicture}[draw=black, ultra thick, x=\Size,y=\Size]
\foreach \col/\colLetter in \Sequence {%
\foreach \row/\rowLetter in \Sequence{%
\pgfmathtruncatemacro{\value}{\col+\NumOfColumns*(\row-1)}
\def\NodeText{\expandafter\csname Node\rowLetter\colLetter\endcsname}
\node [Square] at ($(\col,-\row)-(0.5,0.5)$) {\NodeText};
}
}
\end{tikzpicture}
\end{document}
The following very nice article by Will Robertson published in the PracTeX Journal describes how to make a square cells environment using basic array techniques. I haven't included any specific code for entering the cells; depending on how the cells are generated I might be inclined to use the datatool
package and read in the boards from a CSV file. This would be simple to adapt to this table style.
Square cells: an array cooking lesson
Here's an example:
% This code written by Will Robertson and published in PracTeX Journal 2005-2
% "Square cells: an array cooking lesson"
% Modified for line wrapping
\documentclass{article}
\usepackage{array}
\usepackage{calc}
\newlength\celldim
\newlength\fontheight
\newlength\extraheight
\newcounter{sqcolumns}
\newcolumntype{S}{
@{}
>{\centering \rule[-0.5\extraheight]{0pt}{\fontheight + \extraheight}%
\begin{minipage}{\celldim}\centering}
p{\celldim}
<{\end{minipage}}
@{} }
\newcolumntype{Z}{ @{} >{\centering} p{\celldim} @{} }
\newenvironment{squarecells}[1]
{\setlength\celldim{4.5em}%
\settoheight\fontheight{A}%
\setlength\extraheight{\celldim - \fontheight}%
\setcounter{sqcolumns}{#1 - 1}%
\begin{tabular}{|S|*{\value{sqcolumns}}{Z|}}\hline}
% squarecells tabular goes here
{\end{tabular}}
\newcommand\nl{\tabularnewline\hline}
\begin{document}
\Huge
\begin{squarecells}{4}
This is a long line & 3 & 2 & 13 \nl
5 & 10 & 11 & 8 \nl
9 & 6 & 7 & 12 \nl
4 & 15 & 14 & 1 \nl
\end{squarecells}
\end{document}