# Generate box with content in header

Halo everyone, I intend to create the one as shown in the attached photo as the header of my document using TeX but I can't seem to get it right. Either my box are distorted or they can't be balance on the same line like the one shown in the attached photo. Can anyone show me the correct way if possible in doing this in tex? Flush left and right seem not working to me but being a newbie I can't certain about that.

Following recommendations by Werner, I successfully produce what I am looking for but now the right hand column first row's height got change.

See here:

with my code as shown here:

\fancypagestyle{myheader}{%
\begin{tabular}{|p{2cm}|*{7}{p{5mm}|}}
\hline
\rule{0pt}{1.5em}R.\ No & & & & & & & \\
\hline
\end{tabular}%
}}
\begin{tabular}{|*{5}{>{\centering\arraybackslash}p{5mm}|}}
\hline
1 & 2 & 3 & 4 & \phantom{5} \\ \hline
&   &   &   & \\
\hline
\end{tabular}%
}}
}


So is there any mistake that I had done above?

-
It would be helpful if you posted a full compilable example showing what you have done so far. – Peter Grill Oct 4 '12 at 17:25
@PeterGrill, mine is not successful. I did the above using Paint and move around the picture so that it looks like what I want. – Sandra Oct 4 '12 at 17:49

Here is something you can work with, that uses fancyhdr to set the header of the page.

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{fancyhdr}% http://ctan.org/pkg/fanychdr
\hline
R.\ No & & & & & & & \\
\hline
\end{tabular}%
}
\hline
1 & 2 & 3 & 4 & \phantom{5} \\ \hline
&   &   &   & \\
\hline
\end{tabular}%
}
\renewcommand{\footrulewidth}{0pt}% No footer rule
}
\begin{document}
\lipsum
\end{document}​


geometry is used to easily modify the page layout, adding the required headheight change to accommodate a double-line tabular in the header. lipsum just provides dummy text.

The MWE above provides a myheader page style which you can set for only one page (using \thispagestyle{myheader}) or globally (as is currently done, via \pagestyle{myheader}). You didn't mention anything about a footer, but that can be added to the myheader page style. For example, adding the page number and/or a rule.

To increase the line width for the header tabulars, include the length setting of \arrayrulewidth in a group inside the respective headers. Also the cell widths can be modified by specifying something like p{5mm}, while the height is adjustable via the inclusion of a vertical "strut" using \rule{0pt}{<height>}:

\usepackage{array}% http://ctan.org/pkg/array
\newcommand{\clap}[1]{\makebox[0pt]{#1}}% Centered zero-width box
%...
\begin{tabular}{|p{2cm}|*{7}{c|}}
\hline
\rule{0pt}{1.5em}R.\ No & & & & & & & \\
\hline
\end{tabular}%
}}
\begin{tabular}{|*{5}{>{\centering\arraybackslash}p{5mm}|}}
\hline
\rule{0pt}{1.5em}\clap{1} & \clap{2} & \clap{3} & \clap{4} & \\ \hline
\rule{0pt}{1.5em}  &   &   &   & \\
\hline
\end{tabular}%
}}
\renewcommand{\footrulewidth}{0pt}% No footer rule
}


Note the additional braces that groups the contents and avoids it from spilling into the rest of your document. Any of these height adjustments (rule width and struts) should also be accompanied with a change in headheight to accommodate the increase.

-
may I know why I got this error message when compiled: Some PostScript specials could not be rendered when I try with a document with the above codes except I put in some text like "solutions not available" rather than the \lipsum package? – Sandra Oct 4 '12 at 17:48
And how can I make the columns thicker in its lining just like the picture I show in my first post? The lining in this fancyheader is like normal line. – Sandra Oct 4 '12 at 17:53
@Sandra: Does my example compile without problem? Are you viewing the result in Postscript or PDF format, or perhaps DVI? I've added some information regarding the tabular line width. – Werner Oct 4 '12 at 18:06
Thanks, its getting close to what I am looking for now. For the error message, it only happens when I compile it in DVI form but when I directly compile it into PDF form there is no error. Perhaps DVI could not support it. Now the next issue is how to increase the width and height of the columns? For example the column after S. Name, I suppose to write my name there using pen and there is not enough space for me so I would like to modify the height and width of the columns. Is that possible? Thanks again, Werner. – Sandra Oct 4 '12 at 18:20
@Sandra: I've added a vertical strut to increase the row height. You should use pdflatex or latex->dvips to view the document, since DVI has limited support for content of this sort. – Werner Oct 4 '12 at 18:37