# Align text on top of a framebox

I am trying to create a series of boxes so that my students can input there id number for there final exam.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\newsavebox{\idbox}
\sbox{\idbox}{\framebox[4.5mm]{\vrule depth 1.25mm width 0pt height 2.5mm}}
\newcommand{\nidbox}[1]{%
\foreach \i in {1,...,#1}
{
\usebox{\idbox}\kern-1.5pt
}}
\begin{document}
\nidbox{5}
\end{document}


What I want is to be able to put ID Number directly aligned on top of the first framebox and to be left justified. I have been trying to use \raisebox like:

\def\idnum#1{\raisebox{0.8\baselineskip}[1ex][2ex]{%
ID NUMBER}\kern-4cm #1}


where its implementation would be like \idnum{\nidbox{5}}.

Sincerely I do not know if it is the best approach but I believe that I am forcing it. I know that I can probably do it using a table or with an array but am trying to find out a different approach. Any insights into the matter will be highly appreciated.

-
Question: Is it inappropriate the \raisebox attempt that I was using in my code above? –  azetina Feb 4 '12 at 19:12

I prefer expl3 to tikz for repeating things:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\idbox}{}
{
\framebox[4.5mm]{\vrule depth 1.25mm width 0pt height 2.5mm}
}
\NewDocumentCommand{\idnum}{m}
{
\begin{tabular}{@{}l@{}}
ID~Number\\
\prg_replicate:nn { #1 } { \idbox \hspace{3pt} }
\end{tabular}
}
\ExplSyntaxOff
\begin{document}
\idnum{5}

\idnum{7}
\end{document}


A tabular environment is just the more convenient way to align objects. A tabular free macro could be

\NewDocumentCommand{\idnum}{ m }
{
\vbox:n
{
\hbox:n { \strut ID~Number }
\hbox:n { \strut\prg_replicate:nn { #1 } { \idbox \hspace{3pt} } \unskip }
}
}


But I don't see why one should prefer this approach to the simplicity of a tabular.

-
You have the luxury to prefer one to the other, we mortals can only know a few things at once :) –  percusse Feb 3 '12 at 18:40
Exactly what I was looking for though I was looking for a non-table code. Much appreciated though. Thanks again –  azetina Feb 4 '12 at 19:07
@azetina What's the problem with a tabular? –  egreg Feb 4 '12 at 20:09
@egreg Nothing really am just looking for other ways of doing it. For most stuff I resort to tikz or tabular environments but am trying to find alternatives. –  azetina Feb 6 '12 at 13:25
@azetina A tabular is really the way to go in this case. –  egreg Feb 6 '12 at 13:30

Here is a short non-TikZ solution.

\documentclass{article}
\usepackage{color}
\begin{document}
\makeatletter
\fboxsep8pt
\fboxrule0pt
\@for \next:=A,B,C,D,E\do{
\fbox{\next}%
}

\vspace{-3pt}
\fboxrule1pt
\fboxsep7pt
\@for \next:=A,B,C,D,E\do{
\fbox{\color{white}\next}%
}
\makeatother
\end{document}


It will also work if you change the \@for to \@tfor as follows:

\@tfor \next:=ABCDE\do{
\fbox{\color{white}\next}%
}


-
Thanks a lot for your suggestion. –  azetina Feb 4 '12 at 19:06

It's all Yiannis' fault by mentioning 'non-TikZ' solution :-) Here is a TikZ solution...

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach[count=\xi] \x in {A,...,F}
{
\node[label={[inner sep=1mm]90:\x},draw,inner sep=3mm] (\x) at (\xi,0) {};
}
\end{tikzpicture}
\end{document}


Positioning can be changed via modifying at (\xi,0) with at (0.8*\xi,0) and similarly box sizes can be changed by the second inner sep option. (First defines the distance of the letters from the box.)

-
I love tikz but am looking for alternatives other than it. But thanks for your input –  azetina Feb 4 '12 at 19:08