Create a table with equal-sized cells

With a tikz matrix:

enter image description here

\documentclass{article}
\usepackage[margin=0.5cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}

{
\fontsize{22}{22} \selectfont
\begin{tikzpicture}
  \matrix(table)[
  matrix of nodes,
  row sep =-\pgflinewidth,
  column sep = -\pgflinewidth,
  nodes={anchor=center,
         minimum width=1.25cm, 
         minimum height=1.25cm, 
         },
  ] 
  {X & H & C & M & O & N & O & Y & J & F & O & C & D & L & D \\
T & Z & L & O & B & O & T & O & Q & L & O & T & H & Y & F \\
O & M & W & M & C & L & F & V & S & R & V & L & R & G & I \\
V & Y & C & Y & P & O & D & Y & R & D & X & M & I & E & Z \\
E & K & O & D & V & J & D & E & C & A & B & R & A & E & O \\
J & B & N & X & L & V & P & R & I & L & V & A & C & A & A \\
A & A & E & V & V & G & J & C & I & R & A & Q & U & Y & D \\
W & L & J & S & P & B & B & G & L & L & Y & B & A & N & I \\
G & L & O & F & C & P & Z & V & S & K & O & G & E & L & F \\
A & E & C & L & E & A & T & O & V & P & U & D & J & J & K \\
T & N & H & M & R & T & B & R & R & T & I & C & Z & A & A \\
O & A & G & V & A & F & W & A & R & R & O & F & R & P & B \\
R & I & J & S & N & B & F & O & L & E & O & Z & G & E & J \\
T & Q & R & W & A & U & T & E & O & L & N & I & D & R & W \\
G & B & J & L & E & Y & C & G & E & C & O & P & M & X & J \\
  };
  \draw [black] (table-1-1.north west) -- (table-1-15.north east) -- (table-15-15.south east) -- (table-15-1.south west) -- cycle ;
\end{tikzpicture}
}
\end{document}

Here's a non-TikZ solution. It lets you produce square tables of width (and height) \tablewidth. The first table in the following screeshot uses a width of \textwidth and a font size of 22.74pt (22pt is not available by default unless you add some extra packages); the second table uses a width of 0.5\textwidth and a font size of 9pt.

enter image description here

enter image description here

\documentclass{article}
\usepackage[margin=1cm]{geometry} % set suitable page parameters
\usepackage{tabularx}
    \newcolumntype{C}{>{\centering\arraybackslash}X}
\newlength\tablewidth
\newlength\celldim

\newcommand{\ProduceTable}{%
    \setlength\tabcolsep{0pt}
    \setlength\celldim{\dimexpr(\tablewidth-2\arrayrulewidth)/15\relax}
    \setlength\extrarowheight{\dimexpr\celldim-\baselineskip\relax}
    \centering
    \begin{tabularx}{\tablewidth}{|*{15}{C}|}
    \hline
    X&H&C&M&O&N&O&Y&J&F&O&C&D&L&D \\
    T&Z&L&O&B&O&T&O&Q&L&O&T&H&Y&F \\
    O&M&W&M&C&L&F&V&S&R&V&L&R&G&I \\
    V&Y&C&Y&P&O&D&Y&R&D&X&M&I&E&Z \\
    E&K&O&D&V&J&D&E&C&A&B&R&A&E&O \\
    J&B&N&X&L&V&P&R&I&L&V&A&C&A&A \\
    A&A&E&V&V&G&J&C&I&R&A&Q&U&Y&D \\
    W&L&J&S&P&B&B&G&L&L&Y&B&A&N&I \\
    G&L&O&F&C&P&Z&V&S&K&O&G&E&L&F \\
    A&E&C&L&E&A&T&O&V&P&U&D&J&J&K \\
    T&N&H&M&R&T&B&R&R&T&I&C&Z&A&A \\
    O&A&G&V&A&F&W&A&R&R&O&F&R&P&B \\
    R&I&J&S&N&B&F&O&L&E&O&Z&G&E&J \\
    T&Q&R&W&A&U&T&E&O&L&N&I&D&R&W \\
    G&B&J&L&E&Y&C&G&E&C&O&P&M&X&J \\[1ex]
    \hline
    \end{tabularx}}

\begin{document}

\begin{table}
    \fontsize{20.74}{20.74}\selectfont % '22pt' not available in default font family
    \setlength{\tablewidth}{1\textwidth}
    \ProduceTable
\end{table}

\begin{table}
    \ttfamily
    \fontsize{9}{9}\selectfont 
    \setlength{\tablewidth}{0.5\textwidth} 
    \ProduceTable
\end{table}
\end{document}

Here is another variant, using an ordinary tabular, fixed width m-columns and a 1 cm heigh, 0-width rule redirected (>{}) into a 0-width column (F). m-columns centre the cell contents vertically. I define two new columns (M and F) to clean the code a little bit.

The only additional package you need, is array. I use geometry just to have more sensible margins.

If you prefer a table that adapts to the margins, you calculate the column width using \dimexpr; subtract the width of two array rules (the vertical lines) from the total text width (the distance between the left and right margins), and divide the result by 15. Use the same calculation to find the row height, i.e.:

\newcolumntype{M}{>{\centering\arraybackslash}m{\dimexpr((\textwidth-2\arrayrulewidth)/15)\relax}}
%  The column width
\newcolumntype{F}{>{\rule{0pt}{\dimexpr((\textwidth-2\arrayrulewidth)/15)\relax}}m{0pt}}
%  The row height

Of cause, instead of repeating the calculation, I could have defined a new command, but since it is only two places, I can defend not to do that. I

enter image description here

\documentclass{article}
\usepackage[margin=2cm]{geometry} % set suitable margins
\usepackage{array}

\newcolumntype{M}{>{\centering\arraybackslash}m{1cm}} % Horizontal and vertically 
                                                      % centred cells 
\newcolumntype{F}{>{\rule{0pt}{1cm}}m{0pt}}           % Minimum 1 cm heigh rows 

\begin{document}

  \setlength\tabcolsep{0pt}             % Remove space between columns
  \renewcommand{\arraystretch}{0}       % Remove space between rows 
  \centering
  \fontsize{22}{22}\selectfont          % Gives 22.74pt 
                                        % unless you load a scalable font
  \begin{tabular}{|*{15}{M}|F}
  \hline
  X & H & C & M & O & N & O & Y & J & F & O & C & D & L & D & \\
  T & Z & L & O & B & O & T & O & Q & L & O & T & H & Y & F & \\
  O & M & W & M & C & L & F & V & S & R & V & L & R & G & I & \\
  V & Y & C & Y & P & O & D & Y & R & D & X & M & I & E & Z & \\
  E & K & O & D & V & J & D & E & C & A & B & R & A & E & O & \\
  J & B & N & X & L & V & P & R & I & L & V & A & C & A & A & \\
  A & A & E & V & V & G & J & C & I & R & A & Q & U & Y & D & \\
  W & L & J & S & P & B & B & G & L & L & Y & B & A & N & I & \\
  G & L & O & F & C & P & Z & V & S & K & O & G & E & L & F & \\
  A & E & C & L & E & A & T & O & V & P & U & D & J & J & K & \\
  T & N & H & M & R & T & B & R & R & T & I & C & Z & A & A & \\
  O & A & G & V & A & F & W & A & R & R & O & F & R & P & B & \\
  R & I & J & S & N & B & F & O & L & E & O & Z & G & E & J & \\
  T & Q & R & W & A & U & T & E & O & L & N & I & D & R & W & \\
  G & B & J & L & E & Y & C & G & E & C & O & P & M & X & J & \\
  \hline
  \end{tabular}

\end{document}

Tags:

Tables