-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfancyheadings.doc
205 lines (160 loc) · 8.17 KB
/
fancyheadings.doc
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
Here is a documentstylestyle option that allows you to customize your
page headers and footers in an easy way. It combines features that were
separately available in other pagestyles, without introducing much
complexity. You can define:
- three-part headers and footers
- rules in header and footer
- headers and footers wider than \textwidth
- multiline headers and footers
- separate headers and footers for even and odd pages
- separate headers and footers for chapter pages
To use this pagestyle, you must include the ``fancyheadings'' style
option in your \documentstyle, and issue the \pagestyle{fancy} command.
The \pagestyle{fancy} command should be issued after any changes made to
\textwidth.
The page layout will be as follows:
LHEAD CHEAD RHEAD
----------------------------------- (rule)
page body
----------------------------------- (rule)
LFOOT CFOOT RFOOT
The L-fields will be leftadjusted, the C-fields centered and the
R-fields rightadjusted.
Each of the six fields and the two rules can be defined separately.
Simple use:
The header and footer fields can be defined by commands \lhead{LHEAD}
and so on for the other fields. If the field depends on something in the
document (e.g. section titles) you must in general use the \markboth and
\markright commands, otherwise a title may end on the wrong page. You
can do this e.g. by redefining the commands \chaptermark, \sectionmark
and so on (see example below). The defaults for these marks are as in
the standard pagestyles. The marks can be put into a header or footer
field by referencing \leftmark and \rightmark.
Rules in header and footer
The thickness of the rules below the header and above the footer can be
changed by redefining the length parameters \headrulewidth (default
0.4pt) and \footrulewidth (default 0). These may be redefined by the
\setlength command. A thickness of 0pt makes the rule invisible.
If you want to make more complicated changes, you have to redefine the
commands \headrule and/or \footrule.
E.g. If you want a dotted line rather than a ruler you can give the
command:
\renewcommand{\headrule}{\vbox to 0pt{\hbox to\headwidth{\dotfill}\vss}}
Headers and footers wider than \textwidth
The headers and footers are set in a box of width \headwidth. The
default for this is the value of \textwidth. You can make it wider (or
smaller) by redefining \headwidth with the \setlength or \addtolength
command. The headers and footers will stick out the page on the same
side as the marginal notes. For example to include the marginal notes,
add both \marginparsep and \marginparwidth to \headwidth (see also the
example below).
Multiline headers and footers
Each of the six fields is set in an appropriate parbox, so you can put a
multiline part in it with the \\ command. It is also possible to put
extra space in it with the \vspace command. Note that if you do this you
will probably have to increase the \headheight or \footskip lengths.
Separate headers and footers for even and odd pages
If you want the headers and footers to be different on even- and
odd-numbered pages in the ``twoside'' style, the field-defining macros
can be given an optional argument, to be used on the even-numbered
pages, like \lhead[EVEN-LHEAD]{ODD-LHEAD}.
Separate headers and footers for chapter pages
LaTeX gives a \thispagestyle{plain} command for the first page of the
document, the first page of each chapter and a couple of other pages. It
might be incompatible with your pagestyle. In this case you can use a
slightly different version of the pagestyle, called \pagestyle{fancyplain}.
This pagestyle redefines the pagestyle ``plain'' to also use pagestyle
``fancy'' with the following modifications:
- the thicknesses of the rules is defined by \plainheadrulewidth and
\plainfootrulewidth (both default 0).
- the 6 fields may be defined separately for the plain pages by
giving them the value \fancyplain{PLAIN-VALUE}{NORMAL-VALUE}. This
construct may be used in both the optional argument and the normal
argument. Thus \lhead[\fancyplain{F1}{F2}]{\fancyplain{F3}{F4}}
specifies the LHEAD value in a two-sided document:
F1 on an even-numbered ``plain'' page
F2 on an even-numbered normal page
F3 on an odd-numbered ``plain'' page
F4 on an odd-numbered normal page.
Defaults:
\headrulewidth 0.4pt
\footrulewidth 0pt
\plainheadrulewidth 0pt
\plainfootrulewidth 0pt
\lhead[\fancyplain{}{\sl\rightmark}]{\fancyplain{}{\sl\leftmark}}
% i.e. empty on ``plain'' pages \rightmark on even, \leftmark on odd pages
\chead{}
\rhead[\fancyplain{}{\sl\leftmark}]{\fancyplain{}{\sl\rightmark}}
% i.e. empty on ``plain'' pages \leftmark on even, \rightmark on odd pages
\lfoot{}
\cfoot{\rm\thepage} % page number
\rfoot{}
Examples:
To put two lines containing the section title and the subsection title
in the righthandside corner, use:
\documentstyle[fancyheadings]{article}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markboth{#1}{}}
\renewcommand{\subsectionmark}[1]{\markright{#1}}
\rfoot{\leftmark\\\rightmark}
The following definitions give an approximation of the style used in the
LaTeX book:
\documentstyle[fancyheadings]{book}
\pagestyle{fancyplain}
\addtolength{\headwidth}{\marginparsep}
\addtolength{\headwidth}{\marginparwidth}
\renewcommand{\chaptermark}[1]{\markboth{#1}{#1}} % remember chapter title
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
% section number and title
\lhead[\fancyplain{}{\bf\thepage}]{\fancyplain{}{\bf\rightmark}}
\rhead[\fancyplain{}{\bf\leftmark}]{\fancyplain{}{\bf\thepage}}
\cfoot{}
Using section titles etc. in the headers and/or footers:
You can't just change the header and/or footer fields in the middle of some
text (e.g. after a section header). This is because TeX may have processed
a bit more text before deciding to make up the page. It may have passed a
section beginning, causing the wrong title on the page. TeX has a
mechanism called 'marks' to solve this problem. There is in LaTeX a
\leftmark and a \rightmark. Usually \leftmark is a chapter title and
\rightmark is a section title. To set the marks there are two commands:
\markboth{L}{R} sets the \leftmark to L and the rightmark to R, and
\rightmark{R} sets only the rightmark to R.
The default definitions of \section etc. do this already for you.
An example follows:
left page right page
--------- ----------
2 CHAPTER 1. Introduction | 1.2 Some section 3
------------------------------------ | -----------------------------------------
|
Text | more text
Text | more text
Text | more text
|
|
|
This can be easily done with fancyheadings as follows:
\pagestyle{fancy}
\setlength{\headrulewidth}{1pt}
\lhead[\rm\thepage]{\sl\rightmark}
\rhead[\sl\leftmark]{\rm\thepage}
This specifies that on even pages (the [] parts) the leftheadpart is page
number and rightheadpart is \leftmark, which is the chapter title (because that
is given as the left argument of \markboth (see page 162 of the LaTeX book)
On odd pages (the parts between {}) the leftheadpart is \rightmark (which
is the last section title because that is given as argument to \markright
(see the same page), and the rightheadpart is the page no.
Now suppose you don't want the section number and you want the section
title in upper case:
You add the following to your preamble:
\renewcommand{\sectionmark}[1]{\markright{\uppercase{#1}}}
Or if you don't want the chapter number but only the chapter title (not in
uppercase):
\renewcommand{\chaptermark}[1]{\markboth{#1}{ }}
Note: the parameter in both cases is the (section|chapter) title.
KNOWN PROBLEMS:
Sometimes you will get a warning message from LaTeX concerning ``overfull
vbox during output''. In this case you have to increase the \headheight or
\footskip lengths or both (with \addtolength or \setlength).
If you want to use fancyheadings with the letter style, you must put the
following command in the beginning of your document:
\mark{{}{}}