File: fancyheadings.tex

package info (click to toggle)
tetex-src 3.0.dfsg.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 122,292 kB
  • ctags: 2,709
  • sloc: makefile: 2,323; perl: 1,820; sh: 1,378; lisp: 448; python: 335; xml: 175; sed: 138; ansic: 138; yacc: 52
file content (1467 lines) | stat: -rw-r--r-- 51,397 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
\documentclass[a4paper]{article}
\usepackage{multicol}
\usepackage{float}
\usepackage{makeidx}
\makeindex
\title{Page headers and footers in \LaTeX}
\author{Piet van Oostrum\thanks{A considerable part of this article was
    written by  George
    Gr\"atzer (University of Manitoba) in \emph{Notices Amer. Math. Soc.}
    Thanks, George!}\\
  Dept.\ of Computer Science\\
  Utrecht University}
\def\latex/{\protect\LaTeX{}}
\def\tex/{\TeX}
\def\ams/{\protect\pAmS}
\def\pAmS{{\the\textfont2
        A\kern-.1667em\lower.5ex\hbox{M}\kern-.125emS}}
\def\amslatex/{\ams/-\latex/}
\newcommand{\PSNFSS}{{\sf
    PSNFSS}}
\newcommand{\bs}{\symbol{'134}}
\newcommand{\CmdIndex}[1]{\index{#1@\texttt{\bs#1}}}
\newcommand{\TTindex}[1]{\index{#1@\texttt{#1}}}
\newcommand{\PSindex}[1]{\index{page style!#1@\texttt{#1}}}
\floatstyle{ruled}
\restylefloat{figure}
\renewcommand{\topfraction}{0.9}
\renewcommand{\bottomfraction}{0.9}
\renewcommand{\textfraction}{0.05}
\makeatletter
\renewcommand\l@section      {\@dottedtocline{1}{1.5em}{2.3em}}
\makeatother
\begin{document}
\maketitle
\begin{abstract}
  Standard \latex/ offers the page styles \textsf{empty}, \textsf{plain},
  \textsf{headings} and \textsf{myheadings}. For simple page layouts these
  suffice, but they are rather rigid. A more flexible page layout may be
  obtained by using the  \textsf{fancyheadings} package.
  This article describes how to create advanced page headers and footers
  in \latex/ documents by using this package. Some of the techniques
  described are also applicable with other page styles.
\end{abstract}
\tableofcontents

\section{What is \textsf{fancyheadings}}
The \textsf{fancyheadings} macro package allows you to customize
in \latex/ your page headers and footers in an easy way.  You can
define:
\begin{itemize}
\item three-part headers and footers
\item decorative lines in headers and footers
\item headers and footers wider than the width of the text
\item multi-line headers and footers
\item separate headers and footers for even and odd pages
\item different headers and footers for chapter pages
\end{itemize}

Of course, you also have complete control over fonts, uppercase
and lowercase displays, etc.

\section{Where to get it?}\label{get}
You only need the file \verb|fancyheadings.sty| which you can find at the
\index{ftp}
CTAN sites: \verb|ftp.shsu.edu| (U.S.), \verb|ftp.tex.ac.uk| (U.K.), and
\verb|ftp.dante.de| (Germany).
You will find it in the directory\\
\verb|/tex-archive/macros/latex209/contrib/fancyheadings|. Although
\textsf{fancyheadings}
is a \latex/ 2.09 style file, it will work with \LaTeXe{}. Also this
\TTindex{fixmarks.sty}
\TTindex{extramarks.sty}
article and the two packages \texttt{fixmarks} and \texttt{extramarks} can
be found there. (The code for these packages given in this article is a
simplified version.)


\section{Use of \textsf{fancyheadings}}  To use this package in a
\LaTeXe\ document, place the file \verb|fancyheadings.sty| in a
directory/folder where \tex/ can find it (normally in the input
directory/folder), and include in the preamble of your document
after

\begin{verbatim}
\documentclass{...}
\end{verbatim}
the commands:

\PSindex{fancy}
\begin{verbatim}
\usepackage{fancyheadings}
\pagestyle{fancy}
\end{verbatim}

We can visualize the page layout we can create with \textsf{fancyheadings}
as follows:

\begin{samepage}
\vspace{8pt}
\noindent\makebox[\textwidth]{LeftHeader\hfill
CenteredHeader\hfill RightHeader}
\noindent\makebox[\textwidth]{\hrulefill}\\[\baselineskip]
\noindent\makebox[\textwidth]{\hfill page body\hfill}\\[\baselineskip]
\noindent\makebox[\textwidth]{\hrulefill}
\noindent\makebox[\textwidth]{LeftFooter\hfill
CenteredFooter\hfill RightFooter}

\end{samepage}


\vspace{8pt}

The LeftHeader and LeftFooter are left justified; the
CenteredHeader and CenteredFooter are centered; the
RightHeader and RightFooter are right justified.

We define each of the six ``fields'' and the two decorative lines
separately.

\section{A simple example}  K. Grant is writing a report to Dean
A. Smith, on ``The performance of new graduates'' with the
following page layout:

\begin{samepage}
\vspace{8pt}
\noindent\makebox[\textwidth]{\hfill\bfseries The performance of new
graduates}
\noindent\makebox[\textwidth]{\hrulefill}\\[\baselineskip]
\noindent\makebox[\textwidth]{\hfill page body\hfill}\\[\baselineskip]
\noindent\makebox[\textwidth]{\hrulefill}
\noindent\makebox[\textwidth]{From: K. Grant\phantom{3}\hfill
To: Dean A. Smith\hfill \phantom{From: K. Grant}3}

\end{samepage}

\vspace{8pt}

\noindent where ``3'' is the page number.  The title: ``The
performance of new graduates'' is bold.

This is accomplished by these commands following
\verb|\pagestyle{fancy}|:
\CmdIndex{lhead}
\CmdIndex{rhead}
\CmdIndex{chead}
\CmdIndex{lfoot}
\CmdIndex{rfoot}
\CmdIndex{cfoot}
\CmdIndex{headrulewidth}
\CmdIndex{footrulewidth}
\begin{verbatim}
\lhead{}
\chead{}
\rhead{\bfseries The performance of new graduates}
\lfoot{From: K. Grant}
\cfoot{To: Dean A. Smith}
\rfoot{\thepage}
\setlength{\headrulewidth}{0.4pt}
\setlength{\footrulewidth}{0.4pt}
\end{verbatim}
(The \verb|\thepage| macro displays the current page number.
\verb|\bfseries| is the \LaTeXe's way of selecting bold face.)

This is now fine, except that the first page does not need
all these headers and footers.  To eliminate all but the
centered page number, issue the command

\CmdIndex{thispagestyle}
\begin{verbatim}
\thispagestyle{plain}
\end{verbatim}
after the
\verb|\begin{document}|
and the
\CmdIndex{maketitle}
\verb|\maketitle|
commands.

Alternatively, issue
\begin{verbatim}
\thispagestyle{empty}
\end{verbatim}
if you do not want any headers or footers.

In fact the standard \latex/ classes have the command \verb|\maketitle|
defined in such a way that a \verb|\thispagestyle{plain}| is automatically
issued. So if you \emph{do} want the fancy layout on a page containing
\verb|\maketitle| you must issue a \verb|\thispagestyle{fancy}| after the
\verb|\maketitle|.

\section{An example of two-sided printing}\label{two-sided}

\TTindex{twoside}
Some document classes, such as \verb|book.cls|, print two-sided: the even
pages and the odd pages have different layouts; other document classes
use the \verb|twoside| option to print two-sided.

Now let us print the report two-sided.  Let the above page
layout be used for the odd (right-side) pages, and the
following for the even (left-side) pages:

\begin{samepage}

\vspace{8pt}
\noindent\makebox[\textwidth]{\bfseries The performance of new
graduates\hfill}
\noindent\makebox[\textwidth]{\hrulefill}\\[\baselineskip]
\noindent\makebox[\textwidth]{\hfill page body\hfill}\\[\baselineskip]
\noindent\makebox[\textwidth]{\hrulefill}
\noindent\makebox[\textwidth]{4\phantom{To: Dean A. Smith}\hfill
 From: K. Grant\hfill \phantom{4}To: Dean A. Smith}

\vspace{8pt}

\end{samepage}
\noindent where ``4'' is the page number.

Here are the commands:

\begin{verbatim}
\lhead[]{\bfseries The performance of new graduates}
\chead{}
\rhead[\bfseries The performance of new graduates]{}
\lfoot[\thepage]{From: K. Grant}
\cfoot[From: K. Grant]{To: Dean A. Smith}
\rfoot[To: Dean A. Smith]{\thepage}
\setlength{\headrulewidth}{0.4pt}
\setlength{\footrulewidth}{0.4pt}
\end{verbatim}

As you see, the values of the fields for the even (left-side)
pages are given in the square brackets.  Again, you may
use  \verb|\thispagestyle{plain}| for a simple page layout for
page~1.

\section{Redefining plain style}

Some \latex/ commands, like \verb|\chapter|, use the \verb|\thispagestyle|
command to automatically switch to the \texttt{plain} page style, thus
ignoring the page style currently in effect. To customize even such
pages use the \texttt{fancyplain} page style.  This page style sets up
\texttt{fancy} for normal pages and in addition redefines the page style
\texttt{plain} to conform more to the page style \texttt{fancy}.
\PSindex{plain}
\PSindex{fancyplain}
For instance, if
all the page numbers are bold, you may want this on the first page also.
You do this with the command

\PSindex{fancyplain}
\begin{verbatim}
\pagestyle{fancyplain}
\end{verbatim}
\noindent
Note that this does not issue a \verb|\pagestyle{plain}| or
\verb|\thispagestyle{plain}| command.  This is either done by \latex/ (for
instance, for the first page of a chapter in the \verb|book| class), or you
have to do it explicitly with the

\begin{verbatim}
\thispagestyle{plain}
\end{verbatim}
command.

The redefinition of the plain style is done with the command

\begin{verbatim}
\fancyplain{plain_value}{normal_value}
\end{verbatim}
inserted into all the appropriate arguments.  As an example, let us
redefine the plain style for the report in Section~\ref{two-sided} by
making the page number bold.

The leftheader definition:

\begin{verbatim}
\lhead[]{\bfseries The performance of new graduates}
\end{verbatim}
changes to

\begin{verbatim}
\lhead[\fancyplain{}{}]{\fancyplain{}{\bfseries The
   performance of new graduates}}
\end{verbatim}
Note that the first argument of both \verb|\fancyplain| commands is
empty, since the redefined plain style has an empty leftheader. (The
\verb|\fancyplain{}{}| is superfluous but for symmetry reasons it is given
in this example.)

The left- and rightfooter definitions change more.  For instance, the
leftfooter definition changes from

\begin{verbatim}
\lfoot[\thepage]{From: K. Grant}
\end{verbatim}
to
\begin{verbatim}
\lfoot[\fancyplain{}{\bfseries \thepage}]
      {\fancyplain{}{From: K. Grant}}
\end{verbatim}

Carrying out these changes for all six fields, we get the code:

\label{complicated}
\begin{verbatim}
\lhead[\fancyplain{}{}]{\fancyplain{}{\bfseries The
   performance of new graduates}}
\chead{\fancyplain{}{}}
\rhead[\fancyplain{}{\bfseries The performance of new
   graduates}]{\fancyplain{}{}}
\lfoot[\fancyplain{}{\thepage}]{\fancyplain{}{From: K. Grant}}
\cfoot[\fancyplain{\bfseries \thepage}{From: K.
   Grant}]{\fancyplain{\bfseries \thepage}{To: Dean A. Smith}}
\rfoot[\fancyplain{}{To: Dean A. Smith}]{\fancyplain{}%
   {\bfseries \thepage}}
\setlength{\headrulewidth}{0.4pt}
\setlength{\footrulewidth}{0.4pt}
\end{verbatim}

\PSindex{fancyplain}
For the ``fancy plain'' page style, the thickness of the lines
is defined by
\begin{center}
\CmdIndex{plainheadrulewidth}
\CmdIndex{plainfootrulewidth}
\verb|\plainheadrulewidth| and \verb|\plainfootrulewidth|
\end{center}
\noindent(both default to 0pt).  Observe that you may have
different ``fancy plain'' page styles for even and odd pages.

To use the ``fancy plain'' page style, define these macros; in
the preamble, include

\begin{verbatim}
\usepackage{fancyheadings}
\pagestyle{fancyplain}
\end{verbatim}
and invoke the page style ``fancy plain'' with

\begin{verbatim}
\thispagestyle{plain}
\end{verbatim}
where desired.

\section{The default layout}\label{default}
Let us use the \verb|book.cls| documentclass and the default settings for
\textsf{fancyheadings}; so we only issue the commands

\begin{verbatim}
\usepackage{fancyheadings}
\pagestyle{fancy}
\end{verbatim}
and let \textsf{fancyheadings} take care of everything.  On the
pages where new chapters start, we get a centered page number in
the footer; there is no header, and there are no decorative lines.

On an even page, we get the layout:

\begin{samepage}
\vspace{8pt}
\noindent\makebox[\textwidth]{\sl 1.2  EVALUATION\hfill
 CHAPTER 1. INTRODUCTION}
\noindent\makebox[\textwidth]{\hrulefill}\\[\baselineskip]
\noindent\makebox[\textwidth]{\hfill page body\hfill}\\[\baselineskip]
\noindent\makebox[\textwidth]{\hrulefill}
\noindent\makebox[\textwidth]{\hfill4\hfill}

\end{samepage}

\vspace{8pt}

On an odd page, we get the layout:

\begin{samepage}
\vspace{8pt}
\noindent\makebox[\textwidth]{\sl CHAPTER 1. INTRODUCTION\hfill
 1.2  EVALUATION}
\noindent\makebox[\textwidth]{\hrulefill}\\[\baselineskip]
\noindent\makebox[\textwidth]{\hfill page body\hfill}\\[\baselineskip]
\noindent\makebox[\textwidth]{\hrulefill}
\noindent\makebox[\textwidth]{\hfill
3\hfill }

\end{samepage}


\vspace{8pt}
\noindent where the header text is slanted uppercase.

This default layout is produced by the following commands:
\CmdIndex{rightmark}
\CmdIndex{leftmark}
\begin{verbatim}
\lhead[\fancyplain{}{\slshape \rightmark}]{\fancyplain{}%
   {\slshape \leftmark}}
\chead{}
\rhead[\fancyplain{}{\slshape \leftmark}]{\fancyplain{}%
   {\slshape \rightmark}}
\lfoot{}
\cfoot{\rmfamily \thepage}
\rfoot{}
\end{verbatim}

The following settings are used for the decorative lines:

\begin{tabbing}
\CmdIndex{headrulewidth}
\noindent \verb|\headrulewidth|\qquad \qquad \qquad \=0.4\=pt\\
\CmdIndex{footrulewidth}
\verb|\footrulewidth|\>0\>pt\\
\CmdIndex{plainheadrulewidth}
\verb|\plainheadrulewidth|\>0\>pt\\
\CmdIndex{plainfootrulewidth}
\verb|\plainfootrulewidth| \>0\>pt
\end{tabbing}

The header text is turned into all uppercase in \verb|book.cls|.

\section{The scoop on \latex/'s marks}\label{sec:custom}
Usually, for documents of class \verb|book| and \verb|report|, you may
want to use chapter and section information in the headings (chapter only
for one-sided printing), and for documents of class \verb|article|,
section and subsection information (section only for one-sided
printing).  \latex/ uses a marker mechanism to remember the chapter and
section (section and subsection) information for a page; this is
discussed in detail in the
\latex/ \emph{Companion}, Section 4.3.1.

There are two ways you can use and change the higher- and lower-level
sectioning information available to you.  The macros:
\CmdIndex{rightmark}
\CmdIndex{leftmark}
\verb|\leftmark|
(higher-level) and \verb|\rightmark| (lower-level) contain the information
processed by \latex/, and you can use them directly as shown in 
Section~\ref{default}.

The \verb|\leftmark| contains the left argument of the \emph{last}
\verb|\markboth| on the page, the \verb|\rightmark| contains the right
argument of the \emph{first} \verb|\markboth| or the only argument of the
\emph{first} \verb|\markright| on the page. If no marks are present on a
page they are ``inherited'' from the previous page.

You can influence how chapter, section, and subsection
information (only two of them!) is displayed by redefining the
\CmdIndex{chaptermark}
\verb|\chaptermark|,
\CmdIndex{sectionmark}
\CmdIndex{subsectionmark}
\verb|\sectionmark|, and \verb|\subsectionmark| commands\footnote{There are
  similar commands for \texttt{paragraph} and \texttt{subparagraph} but
  they are seldom used.}. You must put the redefinition
after the first call of \verb|\pagestyle{fancy}| as this
sets up the defaults.

Let us illustrate this with chapter info. It is made up of three parts:
\begin{itemize}
\CmdIndex{thechapter}
\item  the number (say, 2), displayed by the macro \verb|\thechapter|
\item  the name (in English, Chapter), displayed by the macro
\CmdIndex{chaptername}
   \verb|\chaptername|
\item  the title, contained in the first argument of
   \verb|\markboth|.
\end{itemize}

Figure~\ref{fig:markers} shows some variants for ``Chapter 2.\ Do it now''
(the last example is appropriate in some non-English languages).

\begin{figure}[tb]
\CmdIndex{chaptermark}
\CmdIndex{uppercase}
\setlength{\columnsep}{20pt}\small
\begin{multicols}{2}
\noindent Code:\\
\mbox{}\\
\verb|\renewcommand{\chaptermark}[1]{|\\
\verb| \markboth{\chaptername\ |\\
\verb| \thechapter.\ #1}{}}|\\
\mbox{}\\
\verb|\renewcommand{\chaptermark}[1]{|\\
\verb| \markboth{\uppercase{|\\
\verb| \chaptername}\ \thechapter.|\\
\verb| \ #1}{}}|\\
\mbox{}\\
\verb|\renewcommand{\chaptermark}[1]{|\\
\verb| \markboth{\uppercase{|\\
\verb| \chaptername\ \thechapter.|\\
\verb| \ #1}}{}}|\\
\mbox{}\\
\verb|\renewcommand{\chaptermark}[1]{|\\
\verb| \markboth{#1}{}}|\\
\mbox{}\\
\verb|\renewcommand{\chaptermark}[1]{|\\
\verb| \markboth{\thechapter.\ #1}{}}|\\
\mbox{}\\
\verb|\renewcommand{\chaptermark}[1]{|\\
\verb| \markboth{\thechapter.\ |\\
\verb| \chaptername.\ #1}{}}|\\
Prints:\\
\mbox{}\\
Chapter 2.\ Do it now\\
\mbox{}\\
\mbox{}\\
\mbox{}\\
CHAPTER 2.\ Do it now\\
\mbox{}\\
\mbox{}\\
\mbox{}\\
\mbox{}\\
CHAPTER 2.\ DO IT NOW\\
\mbox{}\\
\mbox{}\\
\mbox{}\\
\mbox{}\\
Do it now\\
\mbox{}\\
\mbox{}\\
2.\ Do it now\\
\mbox{}\\
\mbox{}\\
2.\ Chapter.\ Do it now\\
\mbox{}\\
\end{multicols}
\caption{Marker variants}\label{fig:markers}
\end{figure}


For the lower-level sectioning information, do the same with
\verb|\markright|.

So if ``Section 2.2.\ First steps'' is the current section,
then

\begin{verbatim}
\renewcommand{\sectionmark}[1]{
   \markright{\thesection.\ #1}}
\end{verbatim}
will give
   ``2.2.\ First steps''

Redefining the \verb|\chaptermark| and \verb|\sectionmark| commands may
not eliminate all uppercaseness. E.g.\ the bibliography will have a title
\CmdIndex{uppercase}
\index{BIBLIOGRAPHY}
of \textsc{bibliography} in the header, as the \verb|\uppercase| is
explicitly given in the definition of \verb|\thebibliography|. Similar for
\index{INDEX}
\textsc{index} etc.\ If you don't want to redefine these commands, you can
use an ugly hack like the following:

\begin{verbatim}
\lhead{\let\uppercase\relax\rightmark}
\rhead{\let\uppercase\relax\leftmark}
\end{verbatim}


It should be noted that the \latex/ marking mechanism works fine with
chapters (which always start on a new page) and sections (which are
reasonably long).  It does not work quite as well with short sections and
subsections.  This is a problem with \latex/, not with
\textsf{fancyheadings}.

As an example let's take a page layout where the leftmarks are generated by
the sections and the rightmarks by the subsections (as is default in the
\texttt{article} class). Take a page with some short sections, e.g. 

\begin{samepage}
\noindent Section 1.\\
subsection 1.1\\
subsection 1.2\\
Section 2.  
\end{samepage}

As the leftmark contains the \emph{last} mark of the page it will be
``Section 2.'', and the rightmark will be ``subsection 1.1'' as it will be
the \emph{first} mark of the page. So the page header info will combine 
section 2 with subsection 1.1 which isn't very nice.
The best you can do in these cases is use only the \verb|\rightmark|s and
redefine \verb|\sectionmark| accordingly. A \latex/ command
\CmdIndex{firstleftmark}
\verb|\firstleftmark| would also be a nice addition (see the 
\texttt{extramarks} package in section~\ref{sec:xmarks}).

Another problem with the marks in the standard \latex/ classes is that the
higher level sectioning commands (e.g. \verb|\chapter|) call
\verb|\markboth| with an empty right argument. This means that on the first
page of a chapter (or a section in article style) the \verb|\rightmark|
will be empty. If this is a problem you must manually insert extra
\verb|\markright| commands or redefine the \verb|\chaptermark|
(\verb|\sectionmark|) commands to issue a \verb|\markboth| command with
two decent parameters.

As a final remark you should also note that the \verb|*| forms of the
\verb|\chapter| etc.\ commands do \emph{not} call the mark commands. So if
you want your preface to set the header info but not be numbered nor be put in
the table of contents, you must issue the \verb|\markboth| command
yourself, e.g.

\begin{verbatim}
\chapter*{Preface\markboth{Preface}{}}
\end{verbatim}

Entering the \verb|\markboth| command inside the \verb|\chapter*| insures
that the mark will not be separated from the title by a page break. Of
course with \verb|\chapter| this wouldn't be  a problem if you put the mark
command after the chapter title, as the \verb|\chapter| command starts at a
new page. However with a \verb|\section*| it could be dangerous to say:

\begin{verbatim}
\section*{Preface}
\markboth{Preface}{}
\end{verbatim}
as a page break may occur between the two commands.

\section{Dictionary style headers}

\index{dictionary}
\index{concordance}
Dictionaries and concordances usually have a header containing the first
word defined on the page or both the first and the last words. This can
easily be accomplished with \textsf{fancyheadings} and \latex/'s
\texttt{mark} mechanism. Of course if you use the marks for dictionary
style headers, you cannot use them for chapter and section information, so
if there are also chapters and sections present, you must redefine the
\verb|\chaptermark| and \verb|\sectionmark| to make them harmless:

\begin{verbatim}
\renewcommand{\chaptermark}[1]{}
\renewcommand{\sectionmark}[1]{}
\end{verbatim}

Now you do a \verb|\markboth{#1}{#1}| for each dictionary or concordance
entry \verb|#1| and use \verb|\rightmark| for the first entry defined on
the page and \verb|\leftmark| for the last one.

If you want to use a header entry of the form \textsf{firstword--lastword}
it would be nice if this would be reduced to just the form
\textsf{firstword} if both are the same. This could happen if there is just
one entry on the page. In this case a test must be made to check if the
marks are the same.  However, \tex/'s marks are strange beasts, which
cannot be compared out of the box with the plain \tex/ \verb|\if| commands.
\TTindex{ifthen}
Fortunately the \texttt{ifthen} package works well:

\begin{verbatim}
\newcommand{\mymarks}{
  \ifthenelse{\equal{\leftmark}{\rightmark}}
    {\rightmark}
    {\rightmark--\leftmark}}
\lhead[\rm \mymarks]{\rm \thepage}
\rhead[\rm \thepage]{\rm \mymarks}
\end{verbatim}

Dictionaries are often done with two columns. Unfortunately there is a bug
in \latex/'s twocolumn option which causes some marks to be lost. If you
use the  package in figure~\ref{fig:fixmarks}, this will be
solved\footnote{This is a simplification of the  actual code. Get the real
  package from the CTAN sites.}\footnote{The
  \texttt{multicol} package uses a similar technique.}. 

\begin{figure}[tb]
\small
\TTindex{fixmarks.sty}
\begin{verbatim}
% fixmarks.sty:
% Patch LaTeX's output routine to handle marks correctly with two columns.
% Joe Pallas <pallas@edu.stanford.neon>
% Corrected by Piet van Oostrum <piet@cs.ruu.nl> on Feb 5, 1993, Oct 5, 1994

\def\@outputdblcol{\if@firstcolumn \global\@firstcolumnfalse
% Remember the marks from the first column
    \global\setbox\@leftcolumn\copy\@outputbox
    \splitmaxdepth=\maxdimen \cbaddness=10000
    \setbox\@outputbox\vsplit\@outputbox to\maxdimen
    \xdef\@firstcoltopmark{\topmark}%
    \xdef\@firstcolfirstmark{\splitfirstmark}%
    \ifx\@firstcolfirstmark\empty\global\let\@setmarks\relax\else
      \gdef\@setmarks{\let\firstmark\@firstcolfirstmark
        \let\topmark\@firstcoltopmark}%
    \fi
% End of change
  \else \global\@firstcolumntrue
    \setbox\@outputbox\vbox{\hbox to\textwidth{\hbox to\columnwidth
      {\box\@leftcolumn \hss}\hfil \vrule width\columnseprule\hfil
       \hbox to\columnwidth{\box\@outputbox \hss}}}\@combinedblfloats
% Override current first and top with those of first column if necessary
       \@setmarks
% End of change
       \@outputpage \begingroup \@dblfloatplacement \@startdblcolumn
       \@whilesw\if@fcolmade \fi{\@outputpage\@startdblcolumn}\endgroup
    \fi}
\end{verbatim}

  \caption{Fix marks in twocolumn style}
  \label{fig:fixmarks}
\end{figure}

\section{Fancy layouts}

\index{multi-line}
You can make a multi-line field with the \verb|\\| command.  It is also
possible to put extra space in a field with the \verb|\vspace| command.
Note that if you do this you will probably have to increase the height of
\CmdIndex{headheight}
\CmdIndex{footskip}
the header (\verb|\headheight|) or of the footer (\verb|\footskip|),
\index{Overfull \verb|\vbox| \ldots}
otherwise you may get error messages ``Overfull \verb|\vbox| \ldots has occurred while \verb|\output| is active''.
See Section 4.1 of the \latex/ \emph{Companion} for detail.

For instance, the following code will place  the section title and the
subsection title of an article in two lines in the upper right hand
corner:

\begin{verbatim}
\documentclass{article}
\usepackage{fancyheadings}
\pagestyle{fancy}
\addtolength{\headheight}{\baselineskip}
\renewcommand{\sectionmark}[1]{\markboth{#1}{}}
\renewcommand{\subsectionmark}[1]{\markright{#1}}
\rhead{\leftmark\\\rightmark}
\end{verbatim}

You can customize the decorative lines.  You can make the decorative
line in the header quite thick with

\CmdIndex{headrulewidth}
\begin{verbatim}
\setlength{\headrulewidth}{0.6pt}
\end{verbatim}
or you can make the decorative line in the footer disappear with
\CmdIndex{footrulewidth}
\begin{verbatim}
\setlength{\footrulewidth}{0pt}
\end{verbatim}

The decorative lines, themselves, are defined in the two macros
\verb|\headrule| and \verb|\footrule|.  For instance,
if you want a dotted line rather than a solid line in the header,
redefine the command \verb|\headrule|:

\begin{verbatim}
\renewcommand{\headrule}{\vbox to 0pt{\hbox
    to\headwidth{\dotfill}\vss}}
\end{verbatim}

\section{Two book examples}
The following definitions give an approximation of the style
used in L. Lamport's \latex/ book.

Lamport's header overhangs the outside margin.  This is done as follows.

The width of headers and footers is \verb|\headwidth|, which by default
equals the width of the text: \verb|\textwidth|. You can make the width
\CmdIndex{headwidth}
wider (or narrower) by redefining \verb|\headwidth| with the
\verb|\setlength| and \verb|\addtolength| commands.
To overhang the outside margin where the marginal notes are
\CmdIndex{marginparsep}
\CmdIndex{marginparwidth}
printed, add both \verb|\marginparsep| and \verb|\marginparwidth| to
\verb|\headwidth| with the commands:

\begin{verbatim}
\addtolength{\headwidth}{\marginparsep}
\addtolength{\headwidth}{\marginparwidth}
\end{verbatim}

\begin{flushleft}
You must issue these commands \emph{after} the first
\verb|\pagestyle{fancy}| or \verb|\pagestyle{fancyplain}| command as this
will establish the default for \verb|\headwidth|.
\end{flushleft}

And now a complete definition of Lamport's book style:

\begin{verbatim}
\documentclass{book}
\usepackage{fancyheadings}
\pagestyle{fancyplain}
\addtolength{\headwidth}{\marginparsep}
\addtolength{\headwidth}{\marginparwidth}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\lhead[\fancyplain{}{\bfseries\thepage}]
   {\fancyplain{}{\bfseries\rightmark}}
\rhead[\fancyplain{}{\bfseries\leftmark}]
   {\fancyplain{}{\bfseries\thepage}}
\cfoot{}
\end{verbatim}

Notice that the \verb|\chaptermark| and \verb|\sectionmark| commands have
been redefined to eliminate the chapter numbers and the uppercaseness.

For the second example, we take the \amslatex/ book.% \cite{gG93B}.

Chapter pages have no headers or footers.  So we declare

\begin{verbatim}
\thispagestyle{empty}
\end{verbatim}
for every chapter page, and we do not need fancyplain.

Chapter and section titles appear in the form: 2.\ DO IT NOW, so we have
to redefine \verb|\chaptermark| and \verb|\sectionmark| as follows (see
Section~\ref{sec:custom}):

\begin{verbatim}
\renewcommand{\chaptermark}[1]%
   {\markboth{\uppercase{\thechapter.\ #1}}{}}
\renewcommand{\sectionmark}[1]%
   {\markright{\uppercase{\thesection.\ #1}}}
\end{verbatim}

In an even-header, the page number is printed as the LeftHeader and
the chapter info as the RightHeader; in an odd-header, the section info
is printed as the LeftHeader and the page number as the RightHeader.  The
CenteredHeaders are empty.  There are no footers.

There is a decorative line in the header.  It is 0.5pt wide, so we need
the commands:

\begin{verbatim}
\setlength{\headrulewidth}{0.5pt}
\setlength{\footrulewidth}{0pt}
\end{verbatim}

The font used in the headers is 9 pt bold Helvetica.  The \PSNFSS\ system
by Sebastian Rahtz uses the short (Karl Berry) name \verb|phv| for
Helvetica, so this font is selected with the commands:
\begin{verbatim}
\fontfamily{phv}\fontseries{b}\fontsize{9}{11}\selectfont
\end{verbatim}
(See Sections 7.6.1 and 11.9.1 of the \latex/ \emph{Companion}.)
Let us define a shorthand for this:
\begin{verbatim}
\newcommand{\helv}{%
   \fontfamily{phv}\fontseries{b}\fontsize{9}{11}\selectfont}
\end{verbatim}

Now we are ready for the page layout:

\begin{verbatim}
\lhead[\helv \thepage]{\helv \rightmark}
\rhead[\helv \leftmark]{\helv \thepage}
\cfoot{}
\end{verbatim}

Putting this all together:
\begin{verbatim}
\documentclass{book}
\usepackage{fancyheadings}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]%
   {\markboth{\uppercase{\thechapter.\ #1}}{}}
\renewcommand{\sectionmark}[1]%
   {\markright{\uppercase{\thesection.\ #1}}}
\setlength{\headrulewidth}{0.5pt}
\setlength{\footrulewidth}{0pt}
\newcommand{\helv}{%
   \fontfamily{phv}\fontseries{b}\fontsize{9}{11}\selectfont}
\lhead[\helv \thepage]{\helv \rightmark}
\rhead[\helv \leftmark]{\helv \thepage}
\cfoot{}
\end{verbatim}


\section{Special page layout for float pages}
\label{sec:float}

\index{float page}
Some people want to have a special layout for float pages (pages only
containing floats). As these pages
are generated autonomically by \latex/, the user doesn't have any control
over them. There is no \verb|\thispagestyle| for float pages and any change
of the page style will at least also affect the page before the float page.
With fancyheadings you can give the following definition in your
preamble\footnote{If you have \textsf{fancyheadings} version 1.5 or higher
  the commands described in this section are already included}:

\begin{verbatim}
\makeatletter
\def\iffloatpage#1#2{\if@fcolmade #1\else #2\fi}
\makeatother
\end{verbatim}
\CmdIndex{iffloatpage}

In each of
the header- or footer fields you can now specify

\verb|\iffloatpage{|value for float page\verb|}{|value for other pages\verb|}|

You can even use this to get rid of the decorative line on float pages only
by defining:

\begin{verbatim}
\renewcommand{\headrulewidth}{\iffloatpage{0pt}{0.4pt}}
\end{verbatim}

Note that \verb|\renewcommand| is used rather than the usual
\verb|\setlength| command to change the \verb|\headrulewidth|. Changing it
with \verb|\setlength| will not work\footnote{It was probably a dumb
decision to define the width parameters as lengths. There is no need to and
I may change this in a future version of \textsf{fancyheadings}}.

\begin{sloppy}
After this \verb|\renewcommand| it will no longer be possible to change the
parameter \verb|\headrulewidth| with \verb|\setlength|, you will have to use
\verb|\renewcommand| in the rest of the document.
\end{sloppy}

Sometimes you may want to change the layout also for pages that contain a
float on the top of the page or a float on the bottom of the page.

Enter the following definitions in a style file (or between
\verb|\makeatletter| and  \verb|\makeatother| in your preamble:

\begin{verbatim}
\let\latex@makecol\@makecol
\def\@makecol{\let\topfloat\@toplist\let\botfloat\@botlist\latex@makecol}
\def\iftopfloat#1#2{\ifx\topfloat\empty #2\else #1\fi}
\def\ifbotfloat#1#2{\ifx\botfloat\empty #2\else #1\fi}
\end{verbatim}
\CmdIndex{iftopfloat}
\CmdIndex{ifbotfloat}

You can then use the commands \verb|\iftopfloat| and  \verb|\ifbotfloat|
similar to
 \verb|\iffloatpage|.

Note: Marks in floats will not be visible in \latex/'s output routine, so
it is not useful to put marks in floats. So there is currently no way to
let a float (e.g.\ a figure caption) influence the page header or footer.

\section{Those blank pages}
\label{sec:blank}

In the \texttt{book} class when the \texttt{openany} option is not given or
in the \texttt{report} class when the \texttt{openright} option is given,
chapters start at odd-numbered pages, half of the time causing a blank page
to be inserted. Some people prefer this page to be completely empty, i.e.\ 
without headers and footers. This cannot be done with \verb|\thispagestyle|
as this command would have to be issued on the \emph{previous} page. There
is, however, no magic necessary to get this done:

\PSindex{empty}
\CmdIndex{clearpage}
\CmdIndex{cleardoublepage}
\begin{verbatim}
\clearpage{\pagestyle{empty}\cleardoublepage}
\end{verbatim}

As the \verb|\pagestyle{empty}| is enclosed in a group it only affects the
page that may be generated by the \verb|\cleardoublepage|.  You can of
course put the above in a private command. If you want to have this done
automatically at each chapter start or when you want some other text on the
page then you must redefine the \verb|\cleardoublepage| command.
\index{blank page}
\begin{verbatim}
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
  \hbox{}
  \vspace*{\fill}
  \begin{center}
    This page intentionally contains only this sentence.
  \end{center}
  \vspace{\fill}
  \thispagestyle{empty}
  \newpage
  \if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
\end{verbatim}

\section{\textsf{N} of \textsf{M} style page numbers}
\label{sec:nofm}

Some document writers prefer the pages to be numbered as \textsf{n} of
\textsf{m} where \textsf{m} is the number of pages in the document. There
\TTindex{nofm.sty}
is a package \texttt{nofm.sty} available, but some versions of it are
defective, and most don't work with fancyheadings because they take over the
\TTindex{lastpage.sty}
complete page layout. For \LaTeXe{} there is a package \texttt{lastpage}
available which you can use with \textsf{fancyheadings} as follows:

\begin{verbatim}
\usepackage{lastpage}
...
\cfoot{\thepage\ of \pageref{LastPage}}
\end{verbatim}

If you are still using \latex/2.09 and you are not able to switch to
\LaTeXe{} you can define a \latex/2.09 compatible \texttt{lastpage.sty} as
follows:

\begin{verbatim}
\let\origenddocument=\enddocument
\def\enddocument{\clearpage\if@filesw
  {\addtocounter{page}{-1} \immediate\write\@mainaux
    {\string\newlabel{LastPage}{{}{\thepage}}}}\origenddocument}
\end{verbatim}

With some trickery\footnote{If you have a recent version of the
  \texttt{ifthen} package the tricks are not necessary. You can then test
  the \texttt{\char`\\pageref\char`\{LastPage\char`\}} directly.}
 the value of the \texttt{LastPage} label can be used to
make different headers or footers on the last page of a document. E.g.\ if
you want the footer of every odd page, except if it is the last one, to
contain the text ``please turn over'', this can be done as follows:

\begin{verbatim}
\usepackage{lastpage}
\usepackage{ifthen}
...
\makeatletter
\def\LastPagenum{\@ifundefined{r@LastPage}{0}{\expandafter
    \expandafter\expandafter\@cdr
    \csname r@LastPage\endcsname\@nil\null} }
\makeatother
\rfoot{\ifthenelse{\isodd{\value{page}} \and \not
    \value{page}=\LastPagenum}{please turn over}{}}
\end{verbatim}


\section{When to change the headers and footers?}

Sometimes you want to change the header or footer layout in the course of a
document. Some of these changes can be accomplished by using the mark
mechanism as may be seen in section~\ref{sec:custom} and \ref{sec:xmarks}.
However, sometimes we want a more drastic change, e.g to change the page
numbering from roman to arabic (with \verb|\pagenumbering|), to change one of
\index{page style!changes}
the \textsf{fancyheadings} fields or to change to another page style.
Sometimes you may be surprised to find the change to occur too early. In
general the above mentioned changes take effect immediately, i.e.\ on the
page that is currently being built. If you want the change to take effect
at the next page you must make sure that the current page is finished. In
\CmdIndex{clearpage}
most cases this can be done by issuing a \verb|\clearpage| command before
any of the above mentioned changes. If this is not possible you can use the 
\TTindex{afterpage.sty}
\texttt{afterpage} package with:\\
\verb|\afterpage{\lhead{new value}}| or
\CmdIndex{pagenumbering}
\verb|\afterpage{\pagenumbering{roman}}|. You cannot use \verb|\afterpage|
to change the \verb|\pagestyle| as the commands issued by \verb|\afterpage|
are local in a group, and the \verb|\pagestyle| command makes only local
changes. The \verb|\pagenumbering| and the \textsf{fancyheadings} commands
make global changes so they will work, as will the \verb|\thispagestyle|
command. 

It should be noted that although the \textsf{fancyheadings} commands like
\verb|\lhead| take effect immediately, this does not mean that any
``variables'' used in these commands get the value they have at the place
where these commands are given. E.g.\ if \verb|\cfoot{\thepage}| is given
the page number that will be inserted in the footer is not the page number
of the page where this command is given, but rather the page number of
the actual page where the footer is constructed. Of course for the page
number this is what you expect, but it is also true for other commands.

So if you have a book where each chapter is written by a different author
and you want the name of the author in the lower left-hand corner you can
use the following commands:

\begin{verbatim}
\newcommand{\TheAuthor}{}
\newcommand{\Author}[1]{\renewcommand{\TheAuthor}{#1}}
\lfoot{\TheAuthor}
\end{verbatim}

\noindent and start each chapter with the command 
\verb|\Author{Real Name}|.
 If however, the author name would be changed before a page is
completed the wrong author could come in the footer. This would be the case
if you gave the above command \emph{before} the \verb|\chapter| command
rather than after it. 
Another source of problems is the fact that \tex/'s output routine processes
commands ahead, so it may already have processed some commands that produce
text that will appear on the next page. See the next section for an example.

\section{Headers and footers induced by the text}
\label{sec:xmarks}

We have seen how we can use \LaTeX's marks to get information from the
document contents to the headers and footers. The marks mechanism is the
only reliable mechanism that you can use to get changing information to the
headers or footers. This is because \latex/ may be processing your document
ahead before deciding to break the page. 

Sometimes the two marks that \latex/ offers are not enough. An example is
the following:
\begin{quote}
 If a solution to an exercise goes across a page break, then I would like
 to have ``(Continued on next page\ldots)'' at the bottom of the
\index{Continued\ldots}
 first page and ``(Continued\ldots)'' at the top in the margin of the next page.
\end{quote}

You cannot use \latex/'s mark mechanisms for this if you also want to use
chapter and section information.

The code from figure~\ref{fig:xmarks} constitutes a package that gives you
two extra marks that can be used in this situation\footnote{After I made
  this package I discovered a package \texttt{secret.sty} that does a
  similar thing to mark confidential paragraphs if they cross a page
  boundary. It does it, however, by changing the output routine.}.
\begin{figure}[tb]\small
\CmdIndex{extramarks}
\begin{verbatim}
% extramarks.sty
\def\@leftmark#1#2#3#4{#1}
\def\@rightmark#1#2#3#4{#2}

\def\markboth#1#2{{\def\protect{\noexpand\protect\noexpand}
     \let\label\relax \let\index\relax \let\glossary\relax
     \expandafter\@markboth\@themark{#1}{#2}
     \mark{\@themark}}\if@nobreak\ifvmode\nobreak\fi\fi}
\def\markright#1{{\def\protect{\noexpand\protect\noexpand}
     \let\label\relax \let\index\relax \let\glossary\relax
     \expandafter\@markright\@themark
     {#1}\mark{\@themark}}\if@nobreak\ifvmode\nobreak\fi\fi}
\def\@markright#1#2#3#4#5{\gdef\@themark{{#1}{#5}{#3}{#4}}}
\def\@markboth#1#2#3#4#5#6{\gdef\@themark{{#5}{#6}{#3}{#4}}}
\def\leftmark{\expandafter\@leftmark\botmark{}{}{}{}}
\def\rightmark{\expandafter\@rightmark\firstmark{}{}{}{}}
\def\firstleftmark{\expandafter\@leftmark\firstmark{}{}{}{}}
\def\lastrightmark{\expandafter\@rightmark\botmark{}{}{}{}}

\def\@themark{{}{}{}{}}

\def\extramarks#1#2{{\def\protect{\noexpand\protect\noexpand}
     \let\label\relax \let\index\relax \let\glossary\relax
     \expandafter\@markextra\@themark{#1}{#2}
     \mark{\@themark}}\if@nobreak\ifvmode\nobreak\fi\fi}
\def\@markextra#1#2#3#4#5#6{\gdef\@themark{{#1}{#2}{#5}{#6}}}
\def\firstxmark{\expandafter\@firstxmark\firstmark{}{}{}{}}
\def\topxmark{\expandafter\@firstxmark\topmark{}{}{}{}}
\def\lastxmark{\expandafter\@lastxmark\botmark{}{}{}{}}
\def\@firstxmark#1#2#3#4{#3}
\def\@lastxmark#1#2#3#4{#4}
\end{verbatim}
  \caption{Package for extra marks in \latex/}
  \label{fig:xmarks}
\end{figure}
Here is a way to use this package:

\begin{verbatim}
\usepackage{extramarks}
...
\pagestyle{fancy}
\lhead{\firstxmark}
\rfoot{\lastxmark}
...
\extramarks{}{Continued on next page\ldots}
Some text that may or may not cross a page boundary...
\extramarks{Continued\ldots}{}
\end{verbatim}

\CmdIndex{extramarks}
Note that the \verb|\extramarks| command must be close to the text, i.e no
empty lines (paragraph boundaries) should intervene. Otherwise the page may
be broken at that boundary and the extramarks would come on the wrong page.

There are two new marks that can be used in the page layout with this
package: If commands of the form
\verb|\extramarks{|$m_1$\verb|}{|$m_2$\verb|}| are given
\verb|\firstxmark| gives you the first $m_1$ value and
\verb|\lastxmark| gives you the last $m_2$ value
of the current page.
\CmdIndex{firstleftmark}
\CmdIndex{lastrightmark}
It also gives you the \verb|\firstleftmark| and \verb|\lastrightmark|
commands that complement the standard \latex/ marks.

To stress the point that marks are the correct way to do this, let me
give you a ``solution'' that will not work\footnote{Actually there is
  another way but it requires two \latex/ passes: you can put \texttt{\char`\\label}
  commands before and after the text and compare the \texttt{\char`\\pageref}s.}:

\begin{verbatim}
\lhead{Continued}
\rfoot{Continued on next page\ldots}
Some text that may or may not cross a page boundary...
\lhead{}
\rfoot{}
\end{verbatim}

You may be tempted to think that the first \verb|\lhead| and \verb|\rfoot|
will be in effect when \tex/ breaks the page in the middle of the text,
and the last ones when the page breaks after the text. This is not true as
the whole paragraph (including the last definitions) will be processed
\index{page break}
before \tex/ considers the page break, so at the time of the page break the
last definitions are effective, whether the page break occurs inside the text
or outside of it. Putting a paragraph boundary between the
text and the last definitions will not work either, because you don't want
the first definitions to be in effect when \tex/ decides to break the page
exactly at this boundary. Actually the marks mechanism was invented to get
rid of these kinds of problems.

In the above example the text ``Continued'' appears in the page header. It
\index{margin}
may be nicer to put it in the  margin. This can be easily
accomplished by positioning it at a fixed place relative to the page header.
In plain \tex/ you would use a concoction of \verb|\hbox to 0pt|,
\verb|\vbox to 0pt|, \verb|\hskip|,\verb|\vskip|, \verb|\hss| and
\verb|\vss| but fortunately 
\latex/'s \texttt{picture} environment gives a much cleaner way to do this.
In order not to disturb the normal header layout we put the text in a zero-sized
\texttt{picture}. Generally this is the best way to position things on fixed
places on the page. You can then also use the normal headings. See also
section~\ref{sec:thumb} for another example of 
this technique.

\TTindex{picture}
\begin{verbatim}
\setlength{\unitlength}{\baselineskip}
\lhead{\begin{picture}(0,0)
  \put(-2,-3){\makebox(0,0)[r]{\firstxmark}}
  \end{picture}\leftmark}
\end{verbatim}

This solution can of course also be used for the footer. Be sure to put the
\texttt{picture} as the first thing in left-handside entries and last in right-handside
ones.

Finally you may want to put ``(Continued\ldots)'' in the \emph{text}
rather than in the header or the margin. Then you have to use the
\TTindex{afterpage.sty}
\texttt{afterpage} package. We also decide to make a separate
environment for it.

\begin{verbatim}
\newenvironment{continued}{\par
  \extramarks{}{Continued on next page\ldots}
  \afterpage{\noindent\firstxmark\vspace{1ex}}
  }{\extramarks{(Continued\ldots)}{}\par}
\end{verbatim}

It is a bit dangerous to use \verb|\firstxmark| outside the page layout
routine, but apparently with \verb|\afterpage| this works. If you would
need the information further on in the page you must remember the state of
the marks in your own variable. You can do this in one of the
\textsf{fancyheadings} fields. For example if you want to add something
\emph{after} the broken piece of text you can use the following:

\begin{verbatim}
\newcommand{\mysaved}{}

\newenvironment{continued}{\par
  \extramarks{}{Continued on next page\ldots}
  }{\extramarks{(Continued\ldots)}{}\par\vspace{1ex}\mysaved}
\lhead{\leftmark}
\chead{\ifthenelse{\equal{\lastxmark}{}}
  {\gdef\mysaved{}}
  {\gdef\mysaved{\noindent[Continued from previous page]}}}
\end{verbatim}

If you want to include one of the marks or other varying information in the
saved text, you must use \verb|\xdef| rather than \verb|\gdef|.


\section{A movie}

\index{movie}
\TTindex{picture}
If you put at each page on the same place a picture that slightly changes
from page to page you can get a movie-like effect by flipping through the
pages. You can create such a movie easily with fancyheadings. For
simplicity we assume that each picture is in a postscript (EPS) file called
\texttt{pic}$\langle n\rangle$.\texttt{ps} where $\langle n\rangle$ is the page number and that we use
the \texttt{epsf} package. 
\TTindex{epsf}
To put the movie in the  righthandside bottom corner the following will work:

\begin{verbatim}
\rfoot{\setlength{\unitlength}{1mm}\setlength{\epsfxsize}{2cm}
  \begin{picture}(0,0)
    \put(5,0){\epsfbox{pic\thepage.ps}}
  \end{picture}}
\end{verbatim}

Notice that the \verb|\unitlength| and \verb|\epsfxsize| parameter should
be set locally in the fancyheadings field in order to avoid unwanted
interference from their values in the text.

\section{Thumb-indexes}
\label{sec:thumb}

\index{bible}
Some railroad guides and expensive bibles have so called
\index{thumb-index}
\emph{thumb-indexes}, i.e.\ there are marks on the sides of the pages that
indicate where the chapters are. You can create these by printing black
blobs in the margin of the pages. The vertical position should be
determined by the chapter number or some other counter. As the position is
independent of the contents of the page, we print these blobs as part of
the header in a zero-sized \texttt{picture} as described in the previous
section.

Of course we have to take care of two-sided printing, and we may want to
have an index page with all the blobs in the correct position. The solution
requires some hand-tuning to get the blobs nicely spaced out vertically.
For the application that I had there were 12 sections, so I made the blobs
18 mm apart, i.e. 9~mm blob separated by 9~mm whitespace. In order to avoid
calculations they are set in a \texttt{picture} environment with the
\verb|\unitlength| set to 18~mm. Page numbers are set in the headers at the
outer sides, and the blobs are attached to these. In this example the
section numbers are used to position the blobs, but you can replace this
with any numeric value. See figure~\ref{fig:overview} for the resulting
overview page and figure~\ref{fig:thumb} for the code.

\begin{figure}[htb]
\setlength{\unitlength}{9mm}
\newcommand{\blob}{\rule[-.2\unitlength]{1\unitlength}{.5\unitlength}}
\newcounter{line}
\newcommand{\secname}[1]{\addtocounter{line}{1}%
  \put(1,-\value{line}){\blob}
  \put(-7.5,-\value{line}){\arabic{line}}
  \put(-7,-\value{line}){#1}}

\newcommand{\overview}{1
  \begin{picture}(0,0)
    \secname{Introduction}
    \secname{The first year}
    \secname{Specialisation}
  \end{picture}}
 
  \begin{center}
    \leavevmode
    \begin{picture}(11.3,5)
      \put(0,0){\framebox(11.3,5)[tr]{}}
      \put(9,4.5){\overview}
    \end{picture}
  \end{center}
  \caption{Thumb-index overview page}
  \label{fig:overview}
\end{figure}

\begin{figure}[tb]\small
\begin{verbatim}
\setlength{\unitlength}{18mm}
\newcommand{\blob}{\rule[-.2\unitlength]{2\unitlength}{.5\unitlength}}

\newcommand\rblob{\thepage
  \begin{picture}(0,0)
    \put(1,-\value{section}){\blob}
  \end{picture}}

\newcommand\lblob{%
  \begin{picture}(0,0)
    \put(-3,-\value{section}){\blob}
  \end{picture}%
  \thepage}

\pagestyle{fancy}
\cfoot{}

\newcounter{line}
\newcommand{\secname}[1]{\addtocounter{line}{1}%
  \put(1,-\value{line}){\blob}
  \put(-7.5,-\value{line}){\Large \arabic{line}}
  \put(-7,-\value{line}){\Large #1}}

\newcommand{\overview}{\thepage
  \begin{picture}(0,0)
    \secname{Introduction}
    \secname{The first year}
    \secname{Specialisation}
...etc...
  \end{picture}}

\begin{document}
\rhead{\overview}\mbox{}\newpage % This produces the overview page
\rhead{} % Front matter may follow here
\clearpage
\rhead[\rightmark]{\rblob} \lhead[\lblob]{\leftmark}
...
\end{verbatim}
  \caption{Thumb-index code}
  \label{fig:thumb}
\end{figure}


\section{Final Remarks}

The commands to specify the headers and footers are quite complicated when
even- and odd-numbered pages have different layout and we want also to
redefine the \texttt{plain} page style. Therefore for version 2 of
\textsf{fancyheadings} I will create an easier user interface (the old
commands will still work). To give you the opportunity to comment, here is
a preview:

The \verb|*head| and \verb|*foot| commands will be replaced by commands
\verb|\fancyhead| and \verb|\fancyfoot|. These will have an optional
argument that selects which fields to change, e.g. L for the left field, E
for even pages, etc. See figure~\ref{fig:sel}. Selectors can be combined so
\verb|\fancyhead[LE,RO]{text}|
will define the field for both the left header on even pages and the right
header on odd pages.
\begin{figure}[tb]
  \begin{center}
    \leavevmode
    \begin{tabular}{|l|l|}
      \hline
      E & Even page         \\
      O & Odd page          \\
      \hline
      L & Left field        \\
      C & Center field      \\
      R & Right field       \\
      \hline
      T & float at Top      \\
      B & float at Bottom   \\
      F & Float page         \\
      \hline
    \end{tabular}
  \end{center}
  \caption{Selectors}
  \label{fig:sel}
\end{figure}
There will also be a new command \verb|\fancypagestyle| that allows you to
(re)define page styles. One use for this is to redefine the page style
\PSindex{plain}
\PSindex{fancyplain}
\texttt{plain} so the \verb|\fancyplain| stuff is no longer necessary.
Another use is to allow special page styles to be used with
\verb|thispagestyle| or maybe for float pages.

The complicated example in section~\ref{complicated} will then become:

\begin{verbatim}
\fancyhead{} % clear all fields
\fancyhead[LE,RO]{\bfseries The performance of new graduates}}
\fancyfoot[LO,CE]{From: K. Grant}
\fancyfoot[RE,CO]{To: Dean A. Smith}
\fancyfoot[RO,LE]{\bfseries \thepage}
\setlength{\headrulewidth}{0.4pt}
\setlength{\footrulewidth}{0.4pt}

\fancypagestyle{plain}{%
\fancyhead{}
\fancyfoot[C]{\bfseries \thepage}}
\end{verbatim}

As you can see this is much less complicated.

If you want to comment please use e-mail or regular mail to:\\
Piet van Oostrum\\
Dept.\ of Computer Science\\
Utrecht University\\
P.O. Box 80.089\\
3508 TB Utrecht, The Netherlands\\
Telephone: +31 30 531806 Telefax: +31 30 513791\\
Internet: piet@cs.ruu.nl 

\printindex

\end{document}


% Local Variables:
% mode: latex
% TeX-master: t
% End: