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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I make a perfectly square table in LaTeX? Each cell will just have a single character in it. I'm trying to print a pretty tabula recta as shown below.

enter image description here

share|improve this question
Related Question: A table with square cells – Peter Grill Mar 28 '12 at 18:32
up vote 9 down vote accepted

Here's one way to do it.

                \count@\numexpr \trrow + \trcol + `A\relax
                \hbox to\baselineskip{\hss\char\count@\hss}%

                \hsize\dimexpr 27\baselineskip + .4\p@ \relax
                \hbox to\baselineskip{\hfil}%
                        \hbox to\baselineskip{\hss\char\numexpr\trrow + `A\relax\hss}%

Just place a \tabularecta wherever you want it to appear. You can use font size changes like \small if you want. Since the spacing is based entirely on the baseline, you can simply change it using \fontsize{..}{..}\selectfont, or for convenience, you can give \tabularecta an optional argument that is the size you want for each cell.

The implementation is straight forward. It iterates over the rows and then over the columns placing boxes of the appropriate size filled with the desired character inside.

share|improve this answer
@TH Nice implementation of looping through an alphabet. I would use two arguments, one for fontsize and another for baseline, that way you can scale the whole table easily - you never know cryptographers might want to use more than 26 letters! – Yiannis Lazarides Dec 18 '10 at 3:58
Very nice! One question: The .4\p@ are the width of the \vrule, yes? – Hendrik Vogt Dec 18 '10 at 7:58
@Hendrik: Yeah. I'm not even positive that's the right width. I briefly googled, saw that number and plugged it in. Initially, I used \hbox to\z@{\hss\strut\vrule\hss} but then I figured that probably was too crowded. – TH. Dec 18 '10 at 9:06
@Yiannis: Well, you can just change the fontsize before the \tabularecta. E.g., \tiny before it works just fine. – TH. Dec 18 '10 at 9:07

In ConTeXt, you can make each cell of the same height and width by


If you want to see how to generate the output as a loop, have a look at a similar example on the context wiki.

share|improve this answer
I'm afraid I don't know enough (okay, any) ConTeXt to turn that into a compilable example. Will the baselines of each character in the row line up? If so, that's a pretty nice solution. – TH. Dec 18 '10 at 10:09
Yes, the baselines are aligned. Internally, each cell is a framed (one of the core ConTeXt constructs), and the option align={middle, middle} is translated to align=middle and location=lohi. The key location=lohi aligns at the baseline. – Aditya Dec 18 '10 at 16:25

The easiest way possible is to use the tabular environment:

  A &B &C &D &E &F &G\\[1pt]
  A &A &B &C &D &E &F\\[1pt]
  B &B &C &D &E &F &G\\[1pt]
  C &C &D &E &F &G &H\\[1pt]
  D &D &E &F &G &H &I\\[1pt]
  E &E &F &G &H &I &J\\[1pt]
  F &F &G &H &I &J &K\\[1pt]

I added the \\[1pt] to make it look more square (it will depend on the final font size you use). One could also define a short-cut for it to avoid typing it so many times. For me it looks it may take quite a bit of space, so if you want to make the whole thing smaller to fit somewhere, you can enclose it in a \scalebox{0.5}{\begin{tabular}...\end{tabular}}. You get the command \scalebox, by using \usepackage{graphicx}.

share|improve this answer
Well, it's OK, but you'll never get a perfect square like this. – Hendrik Vogt Dec 18 '10 at 7:39

Your Answer


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.