Using the exam document style

Philip Hirschhorn Department of Mathematics Wellesley College Wellesley, MA 02181 phirschhorn@wellesley.edu

December 12, 1994

Contents

1 Introduction 2

2 The documentstyle command 3

3 Questions 3 3.1 Questions with parts and subparts . . . . . . . . . . . . . . . . . . . . . . . 4 3.2 Point values for the questions . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.3 Including special instructions for a group of questions . . . . . . . . . . . . . 9 3.4 Naming the parts of a long exam . . . . . . . . . . . . . . . . . . . . . . . . 12 3.5 Leaving space for the answers . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.6 Changing the page size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

4 Headers and footers 15 4.1 Page styles: Headers and/or footers . . . . . . . . . . . . . . . . . . . . . . . 15 4.2 The three parts of the header . . . . . . . . . . . . . . . . . . . . . . . . . . 16

4.2.1 Using lhead, chead and rhead . . . . . . . . . . . . . . . . . . . . . . 16 4.2.2 Using header, firstpageheader and runningheader . . . . . . . . . . . 18

4.3 The three parts of the footer . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 4.3.1 Using lfoot, cfoot and rfoot . . . . . . . . . . . . . . . . . . . . . . . 19 4.3.2 Using footer, firstpagefooter and runningfooter . . . . . . . . . . . . . 19

4.4 Leaving extra room for multiple line headers and footers . . . . . . . . . . . 20 4.5 Horizontal rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 4.6 Listing the number of pages in the exam . . . . . . . . . . . . . . . . . . . . 22 4.7 Testing for the last page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 4.8 Treating odd and even numbered pages differently . . . . . . . . . . . . . . . 23 4.9 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.9.1 Example: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.9.2 Example: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 4.9.3 Example: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 4.9.4 Example: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

1 Introduction

The file exam.sty provides a document style that attempts to make it easier to prepare exams. Most of what’s here can also be accomplished by using fancyheadings.sty, adjusting LaTEX’s page layout parameters (perhaps by using fullpage.sty) and making careful use of the list environment, but exam.sty tries to make all this as simple as possible.

Specifically, exam.sty sets the page layout so that there are one inch margins all around and provides commands that make it easy to format questions and create very flexible headers and footers. In particular:

• The style will automatically format and number the questions, parts of questions, and subparts of questions, while making it easy to refer to specific questions by number in any special directions you need to print on the exam.

• You can include the point value of each question (or part, or subpart), with your choice of having the point values either at the beginning of the text of the question or in the left margin.

• You can specify the header in three parts: The left head, the center head, and the right head. The left head is left justified, the center head is centered, and the right head is right justified, and one or all of these can be omitted.

• The footer is also specified in three parts: Left justified, centered, and right justified.

• The header and footer for the first page can be different from the ones used on other pages.

• Both headers and footers can contain more than one line. To accommodate headers and footers with many lines, simple commands are provided to increase the parts of the page devoted to the header and/or the footer, and these commands can give one amount of space on the first page and a different amount of space on all other pages.

• You can have a horizontal rule at the base of the header and/or at the top of the footer.

• Macros are defined to allow you to state the total number of pages in the exam and to change the header and/or footer that appears on the last page of the exam.

2 The documentstyle command

To use the exam document style, you should specify exam as your main document style. For example, if you want to use 12 point type, then your documentstyle command should be

                         \documentstyle[12pt]{exam}

If you would also like to use some of the features of AMS-LaTEX, then you should use the command

                     \documentstyle[12pt,amstex]{exam}

3 Questions

To type the questions in the exam, you use the questions environment. Each question is then begun with the command \question, and the questions will be numbered automatically.

For example, if you type

\begin{questions}
\question
Why is there air?
\question
How much wood would a woodchuck chuck if a woodchuck could chuck
wood?
\question
Compute $\displaystyle\int_0^1 x^2 \, dx$.
\end{questions}

then you’ll get

1. Why is there air?

2. How much wood would a woodchuck chuck if a woodchuck could chuck wood?

3. Compute ∫_{0}^{1} x^{2} dx.

As the above example illustrates, you can leave blank lines between the \question command and the actual beginning of the question, or before the first \question command in the environment, and they will be ignored.

3.1 Questions with parts and subparts

If you want a question to have several parts, then you use the parts environment. For example, if you type

\begin{questions}
\question
Why is there air?
\question
What if there were no air?
\begin{parts}
\part
Describe the effect on the balloon industry.
\part
Describe the effect on the aircraft industry.
\end{parts}
\question
\begin{parts}
\part
Define the universe.  Give three examples.
\part
If the universe were to end, how would you know?
\end{parts}

\end{questions}

then you’ll get

1. Why is there air?

2. What if there were no air?

(a) Describe the effect on the balloon industry.

(b) Describe the effect on the aircraft industry.

3. (a) Define the universe. Give three examples.

(b) If the universe were to end, how would you know?

The above example illustrates several things:

• Parts of a question should be put into a parts environment.

• If a question begins with a parts environment, then the first part will appear on the same line with the question number.

• You can leave blank lines before and after the \part command, and they will be ignored.

There is also a subparts environment, and it works just as you would expect. For example, if you type

\begin{questions}
\question
This is the first question.
\question
This is the second question.
\begin{parts}
\part
This is the first part.
\part
This is the second part.
\begin{subparts}
\subpart
This is the first subpart.
\subpart
This is the second subpart.
\subpart
This is the third subpart.
\end{subparts}
\part
This is the third part.
\end{parts}
\question

\begin{parts}
\part
\begin{subparts}
\subpart
This is a subpart.
\subpart
This is another subpart.
\end{subparts}
\part
This is another part.
\end{parts}

\end{questions}

then you’ll get

1. This is the first question.

2. This is the second question.

(a) This is the first part.

(b) This is the second part. i. This is the first subpart. ii. This is the second subpart. iii. This is the third subpart.

(c) This is the third part.

3. (a) i. This is a subpart. ii. This is another subpart.

(b) This is another part.

3.2 Point values for the questions

Each of the commands \question, \part and \subpart take an optional argument, which is the number of points for that question, part, or subpart. The default is that the point value will be inserted at the beginning of the question (or part, or subpart) in parentheses, but if you give the command \pointsinmargin, then the point values will be set in the left margin. For example, if you type

\begin{questions}
\question[20]
Why is there air?

\question
What if there were no air?
\begin{parts}
\part[10]
Describe the effect on the balloon industry.
\part[10]
Describe the effect on the aircraft industry.
\end{parts}
\end{questions}

then, with the default setup, you’ll get

1. (20 points) Why is there air?

2. What if there were no air?

(a) (10 points) Describe the effect on the balloon industry.

(b) (10 points) Describe the effect on the aircraft industry.

If you give the command \pointsinmargin, then the above input will produce instead

1. (20) Why is there air?

2. What if there were no air?

(a) (10) Describe the effect on the balloon industry.

(b) (10) Describe the effect on the aircraft industry.

If you want to switch back and forth between the two formats during the exam, you can do so by giving the commands \pointsinmargin and \nopointsinmargin whenever you want to switch.

Using a substitute for the word “points”

If you want the point value to be inserted at the beginning of the text of the question (i.e., using the default, \nopointsinmargin), but you want to label it with some word other than “points”, then you can change the word inserted by using the \pointname command. If you give the command

                             \pointname{text}

then “text” will be inserted inside the parentheses immediately after the point value. For example, if you give the command

                              \pointname{\%}

and then type

\question[25]
Where, oh where, has my little dog gone?

then you’ll get

1. (25%) Where, oh where, has my little dog gone?

Using the default is equivalent to the command

                            \pointname{ points}

(Note that the space following the point value must be explicitly included.)

Questions that begin with a parts environment

One thing to keep in mind is that only one point value can appear on a line, and it will be the last one to be placed there. This matters only if a question begins with a parts environment, or if a part begins with a subparts environment. In either of these cases, the question number and part number (or the part number and subpart number) will appear on the same line, and if both of these commands include an optional point value, only the last one given will be used. For example, if you type

\begin{questions}
\question[10]
\begin{parts}
\part[5]
This is the first part.
\part[5]
This is the second part.
\end{parts}
\end{questions}

then you’ll get

1. (a) (5 points) This is the first part.

(b) (5 points) This is the second part.

Notice that the 10 points for the entire question are never mentioned anywhere, since they would have appeared on the same line with the 5 points for the first part, and the 5 points for the part were placed later. This is true whether \pointsinmargin or \nopointsinmargin is in effect.

3.3 Including special instructions for a group of questions

There are two commands provided for including special instructions for specific questions: \uplevel and \fullwidth. These commands allow you to give instructions that will be set with the left indentation appropriate for the scope of the instructions.

For example, if you are inside of a parts environment, and you want to give directions for the next few parts, then those directions should be indented to the level of the question of which they are parts, i.e., up one level. If you type

\begin{questions}
\question
This is the first question.
\question
\begin{parts}
\part
This is the first part.
\uplevel{The following two parts should be answered in classical
Greek:}
\part
This is the second part.
\part
This is the third part.
\end{parts}
\end{questions}

then you’ll get

1. This is the first question.

2. (a) This is the first part.

The following two parts should be answered in classical Greek:

(b) This is the second part.

(c) This is the third part.

If you want to give instructions for a group of questions, then the indenting for those instructions should be to the outer left margin, i.e., up one level. For example, if you type

\begin{questions}
\question
Approximate $\displaystyle \int_0^1 \sin x^2 \, dx$ within $.001$ of

its true value.
\uplevel{Questions \ref{exact-start} through~\ref{exact-end} should
be evaluated completely, not just approximated.}
\question
\label{exact-start}
$\displaystyle \int_0^1 \frac{x^2 \, dx}{\sqrt{1-x^2}}$
\question
$\displaystyle \int_0^1 \frac{1}{1+x^2}\, dx$
\question
\label{exact-end}
$\displaystyle \int_0^{\frac{\pi}{2}} \sin^3 x \cos x \, dx$
\end{questions}

you’ll get

1. Approximate ∫_{0}^{1} sin x^{2} dx within .001 of its true value.

Questions 2 through 4 should be evaluated completely, not just approximated.

2. ∫_{0}^{1} \frac{x^{2} dx}{\sqrt{1 − x^{2}}}

3. ∫_{0}^{1} \frac{1}{1 + x^{2}} dx

4. ∫0^{\frac{π}{2}} sin^{3} x cos x dx

If you want to give instructions that use the full width of the page (rather than just going up one level of indentation), then use the \fullwidth command. For example, if you type

\begin{questions}
\question
This is the first question.
\question
\begin{parts}
\part
This is the first part.
\part

This is the second part.
\begin{subparts}
\subpart
This is a subpart.
\fullwidth{When you finish this exam, you should go back and
reexamine your work, both on the earlier part of this exam and in
your life up until the day of this exam, for any errors that you may
have made.}
\subpart
This is another subpart.
\end{subparts}
\end{parts}
\end{questions}

then you’ll get

1. This is the first question.

2. (a) This is the first part.

(b) This is the second part. i. This is a subpart.

When you finish this exam, you should go back and reexamine your work, both on the earlier part of this exam and in your life up until the day of this exam, for any errors that you may have made.

ii. This is another subpart.

Referring to specific questions by number

You can use the standard LaTEX commands \label and \ref to refer to questions (or parts, or subparts) by number. For example, if you type

The first question is question number~\ref{ques:first}, but it's
question number~\ref{ques:second} that has both a good part
(part~\ref{part:good}) and a bad part (part~\ref{part:bad}).
\begin{questions}
\question
\label{ques:first}
This is the first question.
\question
\label{ques:second}

\begin{parts}
\part
\label{part:good}
This is the good part.
\part
\lable{part:bad}
This is the {\em bad\/} part.
\end{parts}
\question
Is there a question?
\end{questions}

then you’ll get:

The first question is question number 1, but it’s question number 2 that has both a good part (part a) and a bad part (part b).

1. This is the first question.

2. (a) This is the good part.

(b) This is the bad part.

3. Is there a question?

As with all other cross references in LaTEX, you’ll have to run your file through LaTEX twice to be sure that all the cross references are correct.

3.4 Naming the parts of a long exam

There are two ways of naming the parts of a long exam. The first way uses the \uplevel and \fullwidth commands (see section 3.3), and the other way uses the standard \part and \section commands.

Using fullwidth and uplevel

To place a section name in the exam, just use a \fullwidth command (see section 3.3) and include whatever font changing commands that you want to use. For example, if you type

\begin{questions}
\question
This is a question in the non-essay part of the exam.
\fullwidth{\Large\bf Essay questions}

\question
Explain how the cooling of matter in the centuries following the big
bang has influenced the British parliamentary system of government.
\fullwidth{\Large\bf Laboratory questions}
\question
In the cabinet below your laboratory bench you will find a single
edged razor blade, several C-clamps, and a bottle of whiskey.  Remove
your appendix.  Do not suture until your work has been inspected.
\end{questions}

then you’ll get

1. This is a question in the non-essay part of the exam.

Essay questions

2. Explain how the cooling of matter in the centuries following the big bang has influenced the British parliamentary system of government.

Laboratory questions

3. In the cabinet below your laboratory bench you will find a single edged razor blade, several C-clamps, and a bottle of whiskey. Remove your appendix. Do not suture until your work has been inspected.

Using the standard sectioning commands

The exam document style is built upon the standard article document style, and so the sectioning commands used with the article document style can be used here as well. In particular, you can give the commands \part, \part*, \section, and \section*. The definitions made in exam.sty ensure that if a \part command appears outside of a parts environment it will be interpreted as a sectioning command, while if it appears inside of a parts environment, it will be interpreted as beginning a new part of a question.

You can give these commands in the middle of a questions environment so as not to interrupt the numbering of the questions, or you can end a questions environment, give a sectioning command, and then start a new questions environment (which would reset the question counter to start again with number 1). If you give any of these commands while inside of a questions environment, then the section titles will be indented to the same extent that questions are indented, unless they are given as the argument of a \fullwidth or \uplevel command. These commands have the advantage, however, that the unstarred versions provide automatic numbering of the parts (or sections).

3.5 Leaving space for the answers

To leave a specific amount of blank space on the page for the answer to a question, you should use the \vspace* command. For example, the command \vspace*{1in} inserts one inch of vertical space after the line in which it appears. (If it appears in between paragraphs, then it inserts the space right there.) You can also use the \vspace command, the difference being that any space inserted by \vspace will be deleted if it occurs at the top of a new page, whereas space inserted by \vspace* will never be deleted.

If you want to equally distribute the blank space among the questions on the page, then just put \vspace*{\fill} after each question on the page and use \newpage to end the page.

3.6 Changing the page size

The exam document style arranges things so that if you print onto standard American letter size paper (8.5 inches wide by 11 inches high) you’ll get one inch margins at the top, bottom and sides. If you want to change the size of these margins (or if you’re printing onto some other size paper), commands are provided to change the size of the printed area.

To change the width of the printed area, you would use the \extrawidth command. The \extrawidth command takes one argument and enlarges the width of the printed area by the amount of the argument. It keeps the printed area centered as it changes its width. If the argument is negative, then the width of the printed area is decreased.

For example, to enlarge the left and right margins by one half inch each, you would use the command

                             \extrawidth{-1in}

since the printed region must shrink by one inch to allow an additional one half inch on both sides. To decrease the left and right margins to three quarters of an inch each, you would use the command

                             \extrawidth{.5in}

since the printed region must grow by one half inch to decrease both margins by one quarter of an inch.

To change the height of the printed area, you must choose whether the top or the bottom of the printed area (or possibly both) should move. The commands for this are principally intended to allow additional room for large headers and footers, and so they are called \extraheadheight and \extrafootheight. For a full description of these commands, see section 4.4.

To move the top of the printed region (and any header that’s present) downwards, you use the command \extraheadheight. This command takes one argument and moves the top of the text and the header down by this amount (keeping the distance between header and text constant). Thus, to increase the top margin by three quarters of an inch, you would give the command

                          \extraheadheight{.75in}

To decrease the top margin by one half inch, you would give the command

                          \extraheadheight{-.5in}

The \extraheadheight command takes an optional argument to provide a top margin on the first page that’s different from that on all other pages. For an explanation of this, see section 4.4.

To move the bottom of the printed region (and any footer that’s present) upwards, you use the command \extrafootheight. This command takes one argument, and moves the bottom of the text and the footer up by this amount (keeping the distance between footer and text constant). Thus, to increase the bottom margin by three quarters of an inch, you would give the command

                          \extrafootheight{.75in}

To decrease the bottom margin by one half inch, you would give the command

                          \extrafootheight{-.5in}

The \extrafootheight command takes an optional argument to provide a bottom margin on the first page that’s different from that on all other pages. For an explanation of this, see section 4.4.

4 Headers and footers

The following sections explain all of the technicalities of the commands that deal with headers and footers. There are a number of things to explain here, and so you may find it easier to skip this section and instead look at the examples in sections 4.9.1 through 4.9.4 (on pages 24 through 27). You can then refer back to the technical sections for the full story on whatever isn’t clear from the examples.

4.1 Page styles: Headers and/or footers

It’s the \pagestyle command that determines whether the exam will have headers, footers, both, or neither. The contents of the header and footer are specified using the commands described in sections 4.2 through 4.5, but it’s the \pagestyle command that determines whether the header and footer that you construct will actually be placed onto the page. The \pagestyle command should be given after the \documentstyle command, and before the

\begin{document}.

To have both a header and a footer, give the command

                          \pagestyle{headandfoot}

If you want every page to have a header but no footer, give the command

                             \pagestyle{head}

To give every page a foot but no head, give the command

                             \pagestyle{foot}

Finally, to omit both the header and the footer from the page, give the command

                             \pagestyle{empty}

As is true in all LaTEX document styles, you can change the page style used on a single page by giving the command

                         \thispagestyle{somestyle}

somewhere on that page (where somestyle is the style that you want to use on that page). This is most often needed if you use the \maketitle command, since that command inserts a \thispagestyle{plain} immediately following the title. If you use the \maketitle command and you want the entire document to use \pagestyle{headandfoot}, then you’ll need

to put the command \thispagestyle{headandfoot} immediately after the \maketitle

command to override the \thispagestyle{plain} that is inserted by \maketitle.

4.2 The three parts of the header

The header is specified in three parts:

• One part to be left justified.

• One part to be centered.

• One part to be right justified.

There are two different ways in which you can specify the three parts of the header. The first uses the commands \lhead, \chead, and \rhead, each of which takes an optional argument to specify a different header for the first page (see section 4.2.1). The second uses the single command \header to specify all three parts of the header, or the commands \firstpageheader and \runningheader to specify a different header for the first page (see section 4.2.2).

4.2.1 Using lhead, chead and rhead

The command \lhead{Text} puts “Text” into the left justified part of the header on every page. The command \lhead[Text 1]{Text 2} puts “Text 1” into the left justified header on the first page and “Text 2” into the left justified header on all other pages. The commands \chead and \rhead have similar effects on the centered and right justified parts of the header.

For example, to put the header

Math 115  Second Exam  July 4, 1776

on every page of the exam, you would give the commands

\lhead{Math 115}
\chead{Second Exam}
\rhead{July 4, 1776}

If you want any of the three parts to have a special version to be used only on the first page, then you just include that special version as an optional argument (enclosed in square brackets) to the command. For example, if you want the above header for the first page, but on all pages after the first you want to have the header

Math 115  Second Exam (Continued)  July 4, 1776

then you would give the commands

\lhead{Math 115}
\chead[Second Exam]{Second Exam (Continued)}
\rhead{July 4, 1776}

You can leave one or more of the three parts empty. To have the header

Math 115  Second Exam  July 4, 1776

on the first page, with the header

Math 115  Second Exam (Continued)

on all other pages, you would give the commands

\pagestyle{headandfoot}
\lhead{Math 115}
\chead[Second Exam]{}
\rhead[July 4, 1776]{Second Exam Continued)}

Any of the three parts of the header can have multiple lines. To specify where the line breaks should go, you just type \\. Thus, to have the header

Math 115 Professor Hilbert

First Exam July 4, 1776

appear on every page, you would give the commands

\lhead{\bf\large Math 115\\Professor Hilbert}
\chead{}
\rhead{\bf\large First Exam\\July 4, 1776}

4.2.2 Using header, firstpageheader and runningheader

The command \header{Text 1}{Text 2}{Text 3} puts “Text 1” into the left justified header, “Text 2” into the centered header and “Text 3” into the right justified header on every page. If you want the header on the first page to be different from that on the other pages, then you should use the commands \firstpageheader and \runningheader, which also take three arguments and affect either the first page or all pages except the first.

For example, to put the header

Math 115  Second Exam  July 4, 1776

on every page of the exam, you would give the command

\header{Math 115}{Second Exam}{July 4, 1776}

If you want to have different header on the first page from the header on all other pages,

you would use the commands \firstpageheader and \runningheader instead of \header.

For example, if you want the above header for the first page, but on all pages after the first you want to have the header

Math 115  Second Exam (Continued)  July 4, 1776

then you would give the commands

\firstpageheader{Math 115}{Second Exam}{July 4, 1776}
\runningheader{Math 115}{Second Exam (Continued)}{July 4, 1776}

You can leave one or more of the three parts empty. To have the header

Math 115  Second Exam  July 4, 1776

on the first page, with the header

Math 115  Second Exam (Continued)

on all other pages, you would give the commands

\firstpageheader{Math 115}{Second Exam}{July 4, 1776}
\runningheader{Math 115}{}{Second Exam (Continued)}

Any of the three parts of the header can have multiple lines. To specify where the line breaks should go, you just type \\. Thus, to have the header

Math 115 Professor Hilbert

First Exam July 4, 1776

appear on every page, you would give the command

\header{\bf\large Math 115\\Professor Hilbert}%
       {}%
       {\bf\large First Exam\\July 4, 1776}

Leaving extra room for multiple line headers

See section 4.4 for a description of the \extraheadheight command.

4.3 The three parts of the footer

The footer is composed of three parts, the whole setup being similar to that for the header (see section 4.2). There are two different ways in which you can specify the three parts of the footer. The first uses the commands \lfoot, \cfoot, and \rfoot, each of which takes an optional argument to specify a different footer for the first page (see section 4.3.1). The second uses the single command \footer to specify all three parts of the footer, or the commands \firstpagefooter and \runningfooter to specify a different footer for the first page (see section 4.3.2).

4.3.1 Using lfoot, cfoot and rfoot

The command \lfoot{Text} puts “Text” into the left justified part of the footer on every page. The command \lfoot[Text 1]{Text 2} puts “Text 1” into the left justified footer on the first page and “Text 2” into the left justified footer on all other pages. The commands \cfoot and \rfoot have similar effects on the centered and right justified parts of the footer.

For example, to have an empty footer on the first page and the footer

Page 3 of 5

on all pages after the first, you would give the commands

\lfoot{}
\cfoot{}
\rfoot[]{Page \thepage\ of \numpages}

(For an explanation of the \numpages command, see section 4.6.)

4.3.2 Using footer, firstpagefooter and runningfooter

The command \footer{Text 1}{Text 2}{Text 3} puts “Text 1” into the left justified footer, “Text 2” into the centered footer and “Text 3” into the right justified footer on every page. If you want the footer on the first page to be different from that on the other pages, then you should use the commands \firstpagefooter and \runningfooter, which also take three arguments and affect either the first page or all pages except the first.

For example, to have an empty footer on the first page and the footer

Page 3 of 5

on all pages after the first, you would give the commands

\firstpagefooter{}{}{}
\runningfooter{}{Page \thepage\ of \numpages}{}

(For an explanation of the \numpages command, see section 4.6.)

Leaving extra room for multiple line footers

See section 4.4 for a description of the \extrafootheight command.

4.4 Leaving extra room for multiple line headers and footers

Headers

If you specify more than one or two lines for any part of the header, then you may want to move the header down slightly so that it doesn’t run off of the top of the paper. The command for this is \extraheadheight. You can also use the \extraheadheight command to adjust the size of the text area. The \extraheadheight command never changes the distance between the header and the text.

For example, to move the header and the text a half inch down from the top of the page, you would give the command

                           \extraheadheight{.5in}

You can also specify a negative distance to extraheadheight to move the header up closer to the top of the paper. For example, the command

                          \extraheadheight{-.25in}

moves the header one quarter inch closer to the top of the paper.

If you want to have a different value for \extraheadheight on the first page from that on the pages after the first, then use the same syntax as in the \lhead, \chead, and \rhead commands: Include an optional argument giving the extra head height for the first page, and the required argument will apply only to those pages after the first. For example, the command

                       \extraheadheight[.5in]{.25in}

gives a half inch of extra head height on the first page and a quarter inch of extra head height on all pages after the first. If you say

                          \extraheadheight[.5in]{}

then this will be interpreted as if it was

                        \extraheadheight[.5in]{0in}

Note that the braces must appear.

If you give an \extraheadheight command, it should be after the \documentstyle command but before the \begin{document} command. The \extraheadheight command can also be used to change the size of the text region (see section 3.6).

Footers

To leave extra room for multiple line footers, you use the command \extrafootheight. Thus, to move the footer one half inch higher up on the paper, you would give the command

                           \extrafootheight{.5in}

If you wanted to move the footer an eighth of an inch lower down on the paper, you would give the command

                         \extrafootheight{-.125in}

If you want to have a different value for \extrafootheight on the first page from that on the pages after the first, then use the same syntax as in the \lfoot, \cfoot, and \rfoot commands: Include an optional argument giving the extra foot height for the first page, and the required argument will apply only to those pages after the first. For example, the command

                       \extrafootheight[.5in]{.25in}

gives a half inch of extra foot height on the first page and a quarter inch of extra foot height on all pages after the first. If you say

                          \extrafootheight[.5in]{}

then this will be interpreted as if it was

                        \extrafootheight[.5in]{0in}

Note that the braces must appear.

If you give an \extrafootheight command, it should be after the \documentstyle command but before the \begin{document} command. The \extrafootheight command can also be used to change the size of the text region (see section 3.6).

4.5 Horizontal rules

The exam document style make it easy to put a horizontal rule under the header and one above the footer. It is also easy to do this for the pages after the first page without affecting the first page.

• The command \runningheadrule puts a horizontal rule below the header on all pages after the first.

• The command \firstpageheadrule puts a rule under the header of only the first page.

• The command \headrule is equivalent to the two commands \firstpageheadrule

     and \runningheadrule.

• The command \runningfootrule puts a horizontal rule above the footer on all pages after the first.

• The command \firstpagefootrule puts a rule above the footer of only the first page.

• The command \footrule is equivalent to the two commands \firstpagefootrule

     and \runningfootrule.

For example, to have the header

Math 115  First Exam  July 4, 1776

on the first page, with the header

Math 115  First Exam  July 4, 1776

on all pages after the first, give the commands

\runningheadrule
\lhead{Math 115}
\chead{First Exam}
\rhead{July 4, 1776}

To have no footer on the first page, and the footer

Page 3 of 5

on all pages after the first, you would give the commands

\runningfootrule
\lfoot{}
\cfoot[]{Page \thepage\ of \numpages}
\rfoot{}

4.6 Listing the number of pages in the exam

The exam document style defines the command \numpages so that it will expand to the number of pages in the exam. Thus, to have the footer

Page 22 of 27

you should give the commands

\lfoot{}
\cfoot{Page \thepage\ of \numpages}
\rfoot{}

For a description of the commands \lfoot, \cfoot, and \rfoot, see section 4.3.

As with all other cross referencing commands in LaTEX, you’ll have to run the file through LaTEX twice to be sure that \numpages is correct.

4.7 Testing for the last page

If you want to vary the text that appears in the header or footer on the last page of the exam, you should use the command \iflastpage. The command

                        \iflastpage{Text 1}{Text 2}

expands to ‘Text 1’ on the last page, and to ‘Text 2’ on all pages before the last. Thus, to have the footer

Please go on to the next page…

on all pages before the last page, and the footer

End of exam

on the last page, you would give the commands

\lfoot{}
\cfoot{\iflastpage{End of exam}{Please go on to the next page\ldots}}
\rfoot{}

For a description of the commands \lfoot, \cfoot, and \rfoot, see section 4.3.

As with all other cross referencing commands in LaTEX, you’ll have to run the file through LaTEX twice to be sure that \iflastpage correctly detects the last page.

4.8 Treating odd and even numbered pages differently

If you’d like odd and even numbered pages to be treated differently (perhaps because you’ll be printing onto both sides of the paper), you should use the \oddeven command.

The \oddeven command takes two arguments. If the current page number is odd it expands to the first argument; otherwise, it expands to the second argument.

For example, to have the page number printed in the right head on odd numbered pages and in the left head on even numbered pages, you would use the commands

\rhead{\oddeven{\thepage}{}}
\lhead{\oddeven{}{\thepage}}
\chead{}

If you wanted the footer of the even numbered pages to be empty and the footer of the odd numbered pages to contain the message “Please continue… ”, except that the last page of the exam should have an empty footer whether its page number is even or odd, then you would use the commands

\lfoot{}
\rfoot{}
\cfoot{\oddeven{\iflastpage{}{Please continue\dots}}{}}

(see section 4.7 for an explanation of \iflastpage).

Although the \oddeven command can be used anywhere in the document (i.e., not just in headers and footers), it is reliable only in headers and footers. This is because LaTEX generally processes more text than can fit on the current page before it outputs a page. When the \oddeven command is encountered it will act as though it will appear on the current page whether it appears on that page or on the following page.

4.9 Examples

4.9.1 Example:

To have the header

Math 115  First Exam  July 4, 1776

on the first page, the header

Math 115  First Exam, Page 2 of 5  July 4, 1776

on all pages after the first, and no footer on any page, give the commands

\pagestyle{head}
\runningheadrule
\lhead{Math 115}
\chead[First Exam]{First Exam, Page \thepage\ of \numpages}
\rhead{July 4, 1776}

Alternatively, you could give the commands

\pagestyle{head}
\runningheadrule
\firstpageheader{Math 115}{First Exam}{July 4, 1776}
\runningheader{Math 115}%
              {First Exam, Page \thepage\ of \numpages}%
              {July 4, 1776}

4.9.2 Example:

To have the header

Mathematics 115 First Exam, July 4, 1776

Name:

on the first page, the header

Mathematics 115 First Exam, July 4, 1776

on all pages after the first, an empty foot on the first page, and the footer

Page 2

on all pages after the first, give the commands

\pagestyle{headandfoot}
\lhead{\large\bf Mathematics 115\\ First Exam, July 4, 1776}
\chead{}
\rhead[\large\bf Name:\enspace\hbox to 2in{\hrulefill}]{}
\lfoot{}
\cfoot[]{Page \thepage}
\rfoot{}

Alternatively, you could give the commands

\pagestyle{headandfoot}
\firstpageheader{\large\bf Mathematics 115\\
                 First Exam, July 4, 1776}%
                {}{\large\bf Name:\enspace\hbox to 2in{\hrulefill}}
\runningheader{\large\bf Mathematics 115\\
               First Exam, July 4, 1776}{}{}
\firstpagefooter{}{}{}
\runningfooter{}{Page \thepage}{}

4.9.3 Example:

To have the header

Wellesley College Second Semester Final Examination, Spring 1993 Mathematics 115

on the first page, the header

Wellesley College Second Semester Final Examination, Spring 1993 Mathematics 115 (Continued)

on all pages after the first, the footer

Page 3 of 10  Please go on to the next page…

on all pages except the last page, and the footer

Page 10 of 10  End of exam.

on the last page, give the commands

\pagestyle{headandfoot}
\extraheadheight{.25in}
\lhead{}
\chead[Wellesley College\\
       Second Semester Final Examination, Spring 1993\\
       Mathematics 115]
      {Wellesley College\\
       Second Semester Final Examination, Spring 1993\\
       Mathematics 115 (Continued)}
\rhead{}
\lfoot{}
\cfoot{Page \thepage\ of \numpages}
\rfoot{\iflastpage{End of exam.}{Please go on to the next page\ldots}}

Alternatively, you could give the commands

\pagestyle{headandfoot}
\extraheadheight{.25in}
\firstpageheader{}{Wellesley College\\
                   Second Semester Final Examination, Spring 1993\\
                   Mathematics 115}{}
\runningheader{}{Wellesley College\\

                 Second Semester Final Examination, Spring 1993\\
                 Mathematics 115 (Continued)}{}
\footer{}{Page \thepage\ of \numpages}%
   {\iflastpage{End of exam.}{Please go on to the next page\ldots}}

4.9.4 Example:

To have the header

Math 115  First Exam  July 4, 1776

on the first page, no header on the pages after the first, no footer on the first page, and the footer

Math 115  First Exam  Page 2 of 5

on all pages after the first, give the commands

\pagestyle{headandfoot}
\runningfootrule
\lhead[Math 115]{}
\chead[First Exam]{}
\rhead[July 4, 1776]{}
\lfoot[]{Math 115}
\cfoot[]{First Exam}
\rfoot[]{Page \thepage\ of \numpages}

Alternatively, you could give the commands

\pagestyle{headandfoot}
\runningfootrule
\firstpageheader{Math 115}{First Exam}{July 4, 1776}
\runningheader{}{}{}
\firstpagefooter{}{}{}
\runningfooter{Math 115}{First Exam}{Page \thepage\ of \numpages}