# Creating static head title for a document class

I am making my own document class in LaTeX but I have a problem on how will I make this title appear automatically when my class is used.

Should I code it this way?

\AtBeginDocument{%
\vspace*{-0.4in}\noindent
{\Large\bfseries School name here} \\
{\large\sffamily college name here} \\[0.2in]
{\Large\sffamily department name here} \\[0.2in]
{\Large\sffamily Subjectcode, subject name here} \\[0.2in]
{\Large\sffamily school year here} \\[0.2in]
\vspace{0.2in}
}

-
A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). It's also not necessary to sign your questions (as there is already a box with your username below it) or to begin them with a greeting. –  Werner Sep 1 '12 at 7:19
Should this be on every page or only on the first page? Only first page: use environment titlepage. –  Kurt Sep 2 '12 at 19:19

Yes. Something like that.

I browsed your profile and saw that you might be interested to write your own class or package so that whenever you use your class or package, your header will automatically be loaded. I can see where you're problem is coming from. It might be that you want to lessen the time you have to type a header like the one you posted whenever you want to make an exam or something like that (which may be your school test paper template or something like that).

You have several options to do this and I list two.

1. Put in a separate file all code that you use frequently then copy and paste as needed.

2. Create a package or a class file at which you have already been given some help but I would also like to point you to the post Style/class tutorials. There is also the related question Put an image header in \documentclass{letter}.

Using option 2 and the links found in the links I have posted here, I have come up with my own document class which automates the inclusion of a school header on the first page and none on the other pages for my class exams and school memos. For your specific problem, you can have a class file with the following contents.

• If you want to have the header simply to appear on the first page without messing with the header, then you can do something like:

\ProvidesClass{myclass}[2012/09/03 version 0.01 My exam class]
\NeedsTeXFormat{LaTeX2e}[1996/06/01]%
\PassOptionsToClass{\CurrentOption}{article}
\ProcessOptions \relax

\RequirePackage[margin=1in]{geometry}
\AtBeginDocument{
\begin{center}
\sffamily
{\Large\textbf{School Name}}\\

{\large\textbf{Name of College}}\\
{\large Name of Department}\\
{\large Subject code, subject name}\\
{\large SY 2012-2013}
\end{center}
\noindent Name: \makebox[3in]{\hrulefill} \hfill Section: \makebox[2in]{\hrulefill}\\
}
\endinput

• If you want to want to use the top margin to save some space, then you can do something like:

\ProvidesClass{myclass}[2012/09/03 version 0.01 My exam class]
\NeedsTeXFormat{LaTeX2e}[1996/06/01]%
\PassOptionsToClass{\CurrentOption}{article}
\ProcessOptions \relax

\RequirePackage[margin=1in]{geometry}
\RequirePackage{fancyhdr}

%% This sets the header of the first page of the letter
\fancypagestyle{firstpage}{%
\fancyhf{} % clear all six fields
\renewcommand{\footrulewidth}{0pt}
\parbox[t][]{4in}{
\centering
\sffamily
{\Large\textbf{School Name}}\\
{\large\textbf{Name of College}}\\
{\large Name of Department}\\
{\large Subject code, subject name}\\
{\large SY 2012-2013}
}}
}
\fancypagestyle{followingpage}{%
\fancyhf{} % clear all six fields
\renewcommand{\footrulewidth}{0pt}
}
\pagestyle{followingpage} % followingpage is the default page style
\AtBeginDocument{\thispagestyle{firstpage} % the page style on the first page
\noindent Name: \makebox[3in]{\hrulefill} \hfill Section: \makebox[2in]{\hrulefill}\\
}

\endinput


Update: September 4. Below is an MWE for testing the classes I have posted here.

\documentclass{myclass}

\usepackage{lipsum}

\begin{document}

\lipsum[1-20]

\end{document}


Below is the output for the second class I posted. You can adjust the dimensions to suit your needs but the idea is there.

-
Hmmm... funny how some of the code still appears this way even if I have tried 4 spaces or highlight then ctrl-K –  hpesoj626 Sep 3 '12 at 4:28
Code inside lists needs eight spaces and not just four. –  Gonzalo Medina Sep 3 '12 at 4:36
@GonzaloMedina, thanks a lot. That explains it. I have now modified my answer to alter the spacing for the code. –  hpesoj626 Sep 3 '12 at 4:41
@hpesoj626: Thank you so much. Its a really big help for beginners like me! But, can you show me a sample output of the second bullet you have posted. I can't really imagine what should it be look like. –  Kayla Sep 3 '12 at 9:13
@Kayla, you are welcome. I have modified my answer. Welcome to TeX.sx! btw. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. You can also accept an answer if you think it is the best answer. You may wait for 24 hours to pass before accepting one so that you can see if there will be some other posts which can answer your questions better. –  hpesoj626 Sep 4 '12 at 1:12