# How do I draw cells around numbers/letters?

Given this:

0 1 2 3

t e s t

How can I draw cells around numbers and letters as well? Of course they also have to be centered.

I tried the table command but I got stuck

\begin{table}[ht]
\caption{Buffer }
\centering
\begin{tabular}{c c c c}

-
Please post a full MWE that can be compiled. Your MWE doesn't contain enough information anyway. E.g. what do you mean by 'cells around numbers and letters'? Each number/letter should be contained in a cell? Are there any spacing requirements? What shape should the cell assume (I guess square)? etc. –  Count Zero Dec 16 '12 at 15:30
Maybe, aside from an MWE, adding a picture of what you are trying to achieve will help. –  hpesoj626 Dec 16 '12 at 15:32
Like Excel cells ...just simple square..Both lines should be aligned –  g9999 Dec 16 '12 at 15:35
Guessing a little from your caption, the following might also be of use: How to draw stack diagram with TikZ. –  Alan Munn Dec 16 '12 at 15:42

For update, scroll down.

Without MWE or picture, I am totally free to flood out my imaginations ;-)

\documentclass{article}

\begin{document}
\begin{tabular}{|c|c|c|c|}\hline
0 & 1 & 2 & 3\\\hline
\end{tabular}

\begin{tabular}{|c|c|c|c|}\hline
t & e & s & t\\\hline
\end{tabular}
\end{document}


# Update:

To make the cells of same width, one can define a new column:

\documentclass{article}
\usepackage{array}
\newcolumntype{M}{>{\centering\arraybackslash}p{.3cm}}
\renewcommand\arraystretch{1.5}
\begin{document}
\begin{tabular}{|*4{M|}}\hline
0 & 1 & 2 & 3\\\hline
\end{tabular}

\begin{tabular}{|*4{M|}}\hline
t & e & s & t\\\hline
\end{tabular}
\end{document}


-
That's exactly what I wanted..test's cells seem to be smaller ..How can I make them as large as the other ones? –  g9999 Dec 16 '12 at 15:41
@g9999: You can include both in the same tabular. –  Werner Dec 16 '12 at 16:42
\documentclass{article}
\usepackage[thinlines]{easytable}
\begin{document}
\begin{TAB}(e){|c|c|c|c|}{|c|c|c|}% horizontan/vertical
0 & 1 & 2 & 3\\
t & e & s & t\\
T & e & s & t
\end{TAB}

\begin{TAB}(e,1cm,1cm,1cm,1cm){|c|c|c|c|}{|c|c|c|}
0 & 1 & 2 & 3\\
t & e & s & t\\
T & e & s & t
\end{TAB}

\end{document}


-
Nice & minimal :) –  Count Zero Dec 16 '12 at 16:14

Here's a more general take on the problem:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x/\cellcontent in {0/t,1/e,2/s,3/t}
\node[draw,shape=rectangle] at (\x,0) {\strut\cellcontent};
\end{tikzpicture}
\end{document}


Like this you can space your cells as far apart as you like and the heights of the boxes will be all equal. Also you could customize your cells: shape, color, etc.

Obvously, it needs you to load TikZ.

EDIT: I extended the above example to show how you could do the cells with a single counter if they contain consecutive numbers:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\foreach \x/\cellcontent in {0/t,1/e,2/s,3/t}
\node[draw,shape=rectangle] at (\x,0) {\strut\cellcontent};
\foreach \x in {1,...,4}
\node[draw,shape=rectangle] at ($(\x-1,2)$) {\strut \x};
\end{tikzpicture}
\end{document}


This will additionally require the calc library of TikZ.

-
Amazing...I'll try it out...immediately –  g9999 Dec 16 '12 at 15:53