1 % fancyhdr.sty version 2.0
2 % Fancy headers and footers for LaTeX.
4 % Dept of Computer and Information Sciences, University of Utrecht,
5 % Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands
6 % Telephone: +31 30 2532180. Email: piet@cs.uu.nl
7 % ========================================================================
9 % This file may be distributed under the terms of the LaTeX Project Public
10 % License, as described in lppl.txt in the base LaTeX distribution.
11 % Either version 1 or, at your option, any later version.
12 % ========================================================================
13 % MODIFICATION HISTORY:
15 % version 1.4: Correction for use with \reversemargin
17 % version 1.5: Added the \iftopfloat, \ifbotfloat and \iffloatpage commands
19 % version 1.6: Reset single spacing in headers/footers for use with
20 % setspace.sty or doublespace.sty
22 % version 1.7: changed \let\@mkboth\markboth to
23 % \def\@mkboth{\protect\markboth} to make it more robust
25 % version 1.8: corrections for amsbook/amsart: define \@chapapp and (more
26 % importantly) use the \chapter/sectionmark definitions from ps@headings if
27 % they exist (which should be true for all standard classes).
29 % version 1.9: The proposed \renewcommand{\headrulewidth}{\iffloatpage...
30 % construction in the doc did not work properly with the fancyplain style.
32 % version 1.91: The definition of \@mkboth wasn't restored on subsequent
33 % \pagestyle{fancy}'s.
35 % version 1.92: The sequence \pagestyle{fancyplain} \pagestyle{plain}
36 % \pagestyle{fancy} would erroneously select the plain version.
38 % version 1.93: \fancypagestyle command added.
40 % version 1.94: suggested by Conrad Hughes <chughes@maths.tcd.ie>
41 % CJCH, Dec 11, 1995: added \footruleskip to allow control over footrule
42 % position (old hardcoded value of .3\normalbaselineskip is far too high
43 % when used with very small footer fonts).
45 % version 1.95: call \@normalsize in the reset code if that is defined,
46 % otherwise \normalsize.
47 % this is to solve a problem with ucthesis.cls, as this doesn't
48 % define \@currsize. Unfortunately for latex209 calling \normalsize doesn't
49 % work as this is optimized to do very little, so there \@normalsize should
50 % be called. Hopefully this code works for all versions of LaTeX known to
53 % version 1.96: initialize \headwidth to a magic (negative) value to catch
54 % most common cases that people change it before calling \pagestyle{fancy}.
55 % Note it can't be initialized when reading in this file, because
56 % \textwidth could be changed afterwards. This is quite probable.
57 % We also switch to \MakeUppercase rather than \uppercase and introduce a
58 % \nouppercase command for use in headers. and footers.
60 % version 1.97: Two changes:
61 % 1. Undo the change in version 1.8 (using the pagestyle{headings} defaults
62 % for the chapter and section marks. The current version of amsbook and
63 % amsart classes don't seem to need them anymore. Moreover the standard
64 % latex classes don't use \markboth if twoside isn't selected, and this is
65 % confusing as \leftmark doesn't work as expected.
66 % 2. include a call to \ps@empty in ps@@fancy. This is to solve a problem
67 % in the amsbook and amsart classes, that make global changes to \topskip,
68 % which are reset in \ps@empty. Hopefully this doesn't break other things.
71 % Added % after the line \def\nouppercase
73 % version 1.99: This is the alpha version of fancyhdr 2.0
74 % Introduced the new commands \fancyhead, \fancyfoot, and \fancyhf.
75 % Changed \headrulewidth, \footrulewidth, \footruleskip to
76 % macros rather than length parameters, In this way they can be
77 % conditionalized and they don't consume length registers. There is no need
78 % to have them as length registers unless you want to do calculations with
79 % them, which is unlikely. Note that this may make some uses of them
80 % incompatible (i.e. if you have a file that uses \setlength or \xxxx=)
83 % Added a few more % signs
86 % Changed the syntax of \f@nfor to be resistent to catcode changes of :=
87 % Removed the [1] from the defs of \lhead etc. because the parameter is
88 % consumed by the \@[xy]lhead etc. macros.
91 % corrected \nouppercase to also include the protected form of \MakeUppercase
92 % \global added to manipulation of \headwidth.
93 % \iffootnote command added.
94 % Some comments added about \@fancyhead and \@fancyfoot.
97 % Changed the default \ps@empty to \ps@@empty in order to allow
98 % \fancypagestyle{empty} redefinition.
101 % Added LPPL license clause.
103 % A check for \headheight is added. An errormessage is given (once) if the
104 % header is too large. Empty headers don't generate the error even if
105 % \headheight is very small or even 0pt.
106 % Warning added for the use of 'E' option when twoside option is not used.
107 % In this case the 'E' fields will never be used.
110 \def\ifancy@mpty#1{\def\temp@a{#1}\ifx\temp@a\@empty}
112 \def\fancy@gdef#1#2{\ifancy@mpty{#2}\gdef#1{\leavevmode}\else\gdef#1{#2\strut}\fi}
113 \def\fancy@ldef#1#2{\ifancy@mpty{#2}\def#1{\leavevmode}\else\def#1{#2\strut}\fi}
115 \let\fancy@def\fancy@gdef
117 \def\@fancyerrmsg#1{%
118 \ifx\PackageError\undefined
120 \PackageError{Fancyhdr}{#1}{}\fi}
121 \def\@fancywarning#1{%
122 \ifx\PackageWarning\undefined
124 \PackageWarning{Fancyhdr}{#1}{}\fi}
126 % Usage: \@forc \var{charstring}{command to be executed for each char}
127 % This is similar to LaTeX's \@tfor, but expands the charstring.
129 \def\@forc#1#2#3{\expandafter\f@rc\expandafter#1\expandafter{#2}{#3}}
130 \def\f@rc#1#2#3{\def\temp@ty{#2}\ifx\@empty\temp@ty\else
131 \f@@rc#1#2\f@@rc{#3}\fi}
132 \def\f@@rc#1#2#3\f@@rc#4{\def#1{#2}#4\f@rc#1{#3}{#4}}
134 % Usage: \f@nfor\name:=list\do{body}
135 % Like LaTeX's \@for but an empty list is treated as a list with an empty
138 \newcommand{\f@nfor}[3]{\edef\@fortmp{#2}%
139 \expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}}
141 % Usage: \def@ult \cs{defaults}{argument}
142 % sets \cs to the characters from defaults appearing in argument
143 % or defaults if it would be empty. All characters are lowercased.
145 \newcommand\def@ult[3]{%
146 \edef\temp@a{\lowercase{\edef\noexpand\temp@a{#3}}}\temp@a
149 {\expandafter\if@in\tmpf@ra\temp@a{\edef#1{#1\tmpf@ra}}{}}%
150 \ifx\@empty#1\def#1{#2}\fi}
152 % \if@in <char><set><truecase><falsecase>
154 \newcommand{\if@in}[4]{%
155 \edef\temp@a{#2}\def\temp@b##1#1##2\temp@b{\def\temp@b{##1}}%
156 \expandafter\temp@b#2#1\temp@b\ifx\temp@a\temp@b #4\else #3\fi}
158 \newcommand{\fancyhead}{\@ifnextchar[{\f@ncyhf h}{\f@ncyhf h[]}}
159 \newcommand{\fancyfoot}{\@ifnextchar[{\f@ncyhf f}{\f@ncyhf f[]}}
160 \newcommand{\fancyhf}{\@ifnextchar[{\f@ncyhf {}}{\f@ncyhf {}[]}}
162 % The header and footer fields are stored in command sequences with
163 % names of the form: \f@ncy<x><y><z> with <x> for [eo], <y> form [lcr]
166 \def\f@ncyhf#1[#2]#3{%
169 {\expandafter\if@in\tmpf@ra{eolcrhf,EOLCRHF}%
170 {}{\edef\temp@c{\temp@c\tmpf@ra}}}%
171 \ifx\@empty\temp@c\else
172 \@fancyerrmsg{Illegal char `\temp@c' in fancyhdr argument:
176 {\def@ult\f@@@eo{eo}\temp@c
178 \if\f@@@eo e\@fancywarning
179 {fancyhdr's E option without twoside option is useless}\fi\fi
180 \def@ult\f@@@lcr{lcr}\temp@c
181 \def@ult\f@@@hf{hf}{#1\temp@c}%
183 {\@forc\f@@lcr\f@@@lcr
185 {\expandafter\fancy@def\csname
186 f@ncy\f@@eo\f@@lcr\f@@hf\endcsname
189 % Fancyheadings version 1 commands. These are more or less deprecated,
190 % but they continue to work.
192 \newcommand{\lhead}{\@ifnextchar[{\@xlhead}{\@ylhead}}
193 \def\@xlhead[#1]#2{\fancy@def\f@ncyelh{#1}\fancy@def\f@ncyolh{#2}}
194 \def\@ylhead#1{\fancy@def\f@ncyelh{#1}\fancy@def\f@ncyolh{#1}}
196 \newcommand{\chead}{\@ifnextchar[{\@xchead}{\@ychead}}
197 \def\@xchead[#1]#2{\fancy@def\f@ncyech{#1}\fancy@def\f@ncyoch{#2}}
198 \def\@ychead#1{\fancy@def\f@ncyech{#1}\fancy@def\f@ncyoch{#1}}
200 \newcommand{\rhead}{\@ifnextchar[{\@xrhead}{\@yrhead}}
201 \def\@xrhead[#1]#2{\fancy@def\f@ncyerh{#1}\fancy@def\f@ncyorh{#2}}
202 \def\@yrhead#1{\fancy@def\f@ncyerh{#1}\fancy@def\f@ncyorh{#1}}
204 \newcommand{\lfoot}{\@ifnextchar[{\@xlfoot}{\@ylfoot}}
205 \def\@xlfoot[#1]#2{\fancy@def\f@ncyelf{#1}\fancy@def\f@ncyolf{#2}}
206 \def\@ylfoot#1{\fancy@def\f@ncyelf{#1}\fancy@def\f@ncyolf{#1}}
208 \newcommand{\cfoot}{\@ifnextchar[{\@xcfoot}{\@ycfoot}}
209 \def\@xcfoot[#1]#2{\fancy@def\f@ncyecf{#1}\fancy@def\f@ncyocf{#2}}
210 \def\@ycfoot#1{\fancy@def\f@ncyecf{#1}\fancy@def\f@ncyocf{#1}}
212 \newcommand{\rfoot}{\@ifnextchar[{\@xrfoot}{\@yrfoot}}
213 \def\@xrfoot[#1]#2{\fancy@def\f@ncyerf{#1}\fancy@def\f@ncyorf{#2}}
214 \def\@yrfoot#1{\fancy@def\f@ncyerf{#1}\fancy@def\f@ncyorf{#1}}
217 \newcommand{\headrulewidth}{0.4pt}
218 \newcommand{\footrulewidth}{\z@skip}
219 \newcommand{\footruleskip}{.3\normalbaselineskip}
221 % Fancyplain stuff shouldn't be used anymore (rather
222 % \fancypagestyle{plain} should be used), but it must be present for
223 % compatibility reasons.
225 \newcommand{\plainheadrulewidth}{\z@skip}
226 \newcommand{\plainfootrulewidth}{\z@skip}
227 \newif\if@fancyplain \@fancyplainfalse
228 \def\fancyplain#1#2{\if@fancyplain#1\else#2\fi}
230 \headwidth=-123456789sp %magic constant
232 % Command to reset various things in the headers:
233 % a.o. single spacing (taken from setspace.sty)
234 % and the catcode of ^^M (so that epsf files in the header work if a
235 % verbatim crosses a page boundary)
236 % It also defines a \nouppercase command that disables \uppercase and
237 % \Makeuppercase. It can only be used in the headers and footers.
238 \def\fancy@reset{\restorecr
239 \def\baselinestretch{1}%
240 \def\nouppercase##1{{\let\uppercase\relax\let\MakeUppercase\relax
241 \expandafter\let\csname MakeUppercase \endcsname\relax##1}}%
242 \ifx\undefined\@newbaseline% NFSS not present; 2.09 or 2e
243 \ifx\@normalsize\undefined \normalsize % for ucthesis.cls
244 \else \@normalsize \fi
245 \else% NFSS (2.09) present
249 % Initialization of the head and foot text.
251 % The default values still contain \fancyplain for compatibility.
252 \fancyhf{} % clear all
253 % lefthead empty on ``plain'' pages, \rightmark on even, \leftmark on odd pages
254 % evenhead empty on ``plain'' pages, \leftmark on even, \rightmark on odd pages
256 \fancyhead[el,or]{\fancyplain{}{\sl\rightmark}}
257 \fancyhead[er,ol]{\fancyplain{}{\sl\leftmark}}
259 \fancyhead[l]{\fancyplain{}{\sl\rightmark}}
260 \fancyhead[r]{\fancyplain{}{\sl\leftmark}}
262 \fancyfoot[c]{\rm\thepage} % page number
264 % Use box 0 as a temp box and dimen 0 as temp dimen.
265 % This can be done, because this code will always
266 % be used inside another box, and therefore the changes are local.
268 \def\@fancyvbox#1#2{\setbox0\vbox{#2}\ifdim\ht0>#1\@fancywarning
269 {\string#1 is too small (\the\headheight): ^^J Make it at least \the\ht0.^^J
270 We now make it that large for the rest of the document.^^J
271 This may cause the page layout to be inconsistent, however\@gobble}%
272 \dimen0=#1\global\setlength{#1}{\ht0}\ht0=\dimen0\fi
275 % Put together a header or footer given the left, center and
276 % right text, fillers at left and right and a rule.
277 % The \lap commands put the text into an hbox of zero size,
278 % so overlapping text does not generate an errormessage.
279 % These macros have 5 parameters:
280 % 1. \@lodd or \@rodd % This determines at which side the header will stick
282 % 2. \f@ncyolh, \f@ncyelh, \f@ncyolf or \f@ncyelf. This is the left component.
283 % 3. \f@ncyoch, \f@ncyech, \f@ncyocf or \f@ncyecf. This is the middle comp.
284 % 4. \f@ncyorh, \f@ncyerh, \f@ncyorf or \f@ncyerf. This is the right component.
285 % 5. \@lodd or \@rodd % This determines at which side the header will stick
286 % out. This is the reverse of parameter nr. 1. One of them is always
287 % \relax and the other one is \hss (after expansion).
289 \def\@fancyhead#1#2#3#4#5{#1\hbox to\headwidth{\fancy@reset
290 \@fancyvbox\headheight{\hbox
291 {\rlap{\parbox[b]{\headwidth}{\raggedright#2}}\hfill
292 \parbox[b]{\headwidth}{\centering#3}\hfill
293 \llap{\parbox[b]{\headwidth}{\raggedleft#4}}}\headrule}}#5}
295 \def\@fancyfoot#1#2#3#4#5{#1\hbox to\headwidth{\fancy@reset
296 \@fancyvbox\footskip{\footrule
297 \hbox{\rlap{\parbox[t]{\headwidth}{\raggedright#2}}\hfill
298 \parbox[t]{\headwidth}{\centering#3}\hfill
299 \llap{\parbox[t]{\headwidth}{\raggedleft#4}}}}}#5}
301 \def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
302 \hrule\@height\headrulewidth\@width\headwidth \vskip-\headrulewidth}}
304 \def\footrule{{\if@fancyplain\let\footrulewidth\plainfootrulewidth\fi
305 \vskip-\footruleskip\vskip-\footrulewidth
306 \hrule\@width\headwidth\@height\footrulewidth\vskip\footruleskip}}
309 \@ifundefined{@chapapp}{\let\@chapapp\chaptername}{}%for amsbook
311 % Define \MakeUppercase for old LaTeXen.
312 % Note: we used \def rather than \let, so that \let\uppercase\relax (from
313 % the version 1 documentation) will still work.
315 \@ifundefined{MakeUppercase}{\def\MakeUppercase{\uppercase}}{}%
316 \@ifundefined{chapter}{\def\sectionmark##1{\markboth
317 {\MakeUppercase{\ifnum \c@secnumdepth>\z@
318 \thesection\hskip 1em\relax \fi ##1}}{}}%
319 \def\subsectionmark##1{\markright {\ifnum \c@secnumdepth >\@ne
320 \thesubsection\hskip 1em\relax \fi ##1}}}%
321 {\def\chaptermark##1{\markboth {\MakeUppercase{\ifnum \c@secnumdepth>\m@ne
322 \@chapapp\ \thechapter. \ \fi ##1}}{}}%
323 \def\sectionmark##1{\markright{\MakeUppercase{\ifnum \c@secnumdepth >\z@
324 \thesection. \ \fi ##1}}}}%
325 %\csname ps@headings\endcsname % use \ps@headings defaults if they exist
327 \gdef\ps@fancy{\@fancyplainfalse\ps@@fancy}%
328 % Initialize \headwidth if the user didn't
332 % This catches the case that \headwidth hasn't been initialized and the
333 % case that the user added something to \headwidth in the expectation that
334 % it was initialized to \textwidth. We compensate this now. This loses if
335 % the user intended to multiply it by a factor. But that case is more
336 % likely done by saying something like \headwidth=1.2\textwidth.
337 % The doc says you have to change \headwidth after the first call to
338 % \pagestyle{fancy}. This code is just to catch the most common cases were
339 % that requirement is violated.
341 \global\advance\headwidth123456789sp\global\advance\headwidth\textwidth
343 \def\ps@fancyplain{\ps@fancy \let\ps@plain\ps@plain@fancy}
344 \def\ps@plain@fancy{\@fancyplaintrue\ps@@fancy}
345 \let\ps@@empty\ps@empty
347 \ps@@empty % This is for amsbook/amsart, which do strange things with \topskip
348 \def\@mkboth{\protect\markboth}%
349 \def\@oddhead{\@fancyhead\@lodd\f@ncyolh\f@ncyoch\f@ncyorh\@rodd}%
350 \def\@oddfoot{\@fancyfoot\@lodd\f@ncyolf\f@ncyocf\f@ncyorf\@rodd}%
351 \def\@evenhead{\@fancyhead\@rodd\f@ncyelh\f@ncyech\f@ncyerh\@lodd}%
352 \def\@evenfoot{\@fancyfoot\@rodd\f@ncyelf\f@ncyecf\f@ncyerf\@lodd}%
354 \def\@lodd{\if@reversemargin\hss\else\relax\fi}
355 \def\@rodd{\if@reversemargin\relax\else\hss\fi}
358 \let\latex@makecol\@makecol
359 \def\@makecol{\ifvoid\footins\footnotetrue\else\footnotefalse\fi
360 \let\topfloat\@toplist\let\botfloat\@botlist\latex@makecol}
361 \def\iftopfloat#1#2{\ifx\topfloat\empty #2\else #1\fi}
362 \def\ifbotfloat#1#2{\ifx\botfloat\empty #2\else #1\fi}
363 \def\iffloatpage#1#2{\if@fcolmade #1\else #2\fi}
365 \newcommand{\fancypagestyle}[2]{%
366 \@namedef{ps@#1}{\let\fancy@def\fancy@ldef#2\relax\ps@fancy}}