Align text on top of a framebox
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}%
}
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
.
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.)