-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample25.tex
293 lines (240 loc) · 9.67 KB
/
example25.tex
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
\documentclass[openany]{book}
\usepackage{lipsum}
\usepackage{boxedminipage}
\usepackage{ifthen}
\usepackage{refcount}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[LE,RO]{\textsl{\rightmark}}
\fancyhead[LO,RE]{\textsl{\leftmark}}
\fancyfoot[C]{\thepage}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\fancypagestyle{myfancy}{
\fancyhead[LE,RO]{MYFANCY SECTION}
% The rest is inherited from fancy
}
\fancypagestyle{switch}{
\fancyhead[LE,RO]{%
\ifthenelse{\value{page}=\getpagerefnumber{otherpagestyle}}
{MYFANCY SECTION}
{\textsl{\rightmark}}}
% The rest is inherited from pagestyle fancy
}
\newcommand{\strutheader}{%
\texttt{\textbackslash strut}:
\rule[-0.3\normalbaselineskip]{10pt}{0.3\normalbaselineskip}%
\rule{10pt}{0.7\normalbaselineskip}
\texttt{\textbackslash headruleskip}$\searrow$
\raisebox{-0.3\normalbaselineskip}[0pt][0pt]%
{\ifdim \headruleskip>0pt
\rule[-\headruleskip]{10pt}{\headruleskip}
\else
\rule{10pt}{-\headruleskip}
\fi}
}
\newcommand{\strutfooter}{%
\raisebox{0pt}[0pt][0pt]{%
\texttt{\textbackslash strut}:
\rule[-0.3\normalbaselineskip]{10pt}{0.3\normalbaselineskip}%
\rule{10pt}{0.7\normalbaselineskip}
\texttt{\textbackslash footruleskip} $\nearrow$
\rule[0.7\normalbaselineskip]{10pt}{\footruleskip}}%
}
\fancypagestyle{showstruts}{%
\fancyhead[L]{%
\ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
{\strutheader}%
{\rightmark}%
}
\fancyfoot[L]{%
\ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
{\strutfooter}%
{}%
}
\fancyheadinit{%
\ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
{\renewcommand{\headruleskip}{4pt}}%
{\renewcommand{\headruleskip}{0pt}}%
}
\fancyfootinit{%
\ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
{\renewcommand{\footrulewidth}{0.4pt}}%
{\renewcommand{\footrulewidth}{0pt}}%
}
}
\newcommand{\cs}[1]{\texttt{\char`\\#1}}
\begin{document}
\tableofcontents
\newpage
\thispagestyle{plain}
\noindent
\begin{boxedminipage}{\textwidth}
This is example 25 in the fancyhdr documentation.
In chapter~\ref{ch:just-thispagestyle} it demonstrates \cs{thispagestyle}, both a good and a bad example.
In chapter~\ref{ch:pageref} it gives a better solution to change the page style in the middle of a text. This is example 25~(a) in the \textsf{fancyhdr} documentation.
Finally, chapter~\ref{ch:showstruts} gives the code for the ``\emph{showstruts}'' example 25~(b) in the documentation.
The normal page style in this document is:
\begin{verbatim}
\pagestyle{fancy}
\fancyhead[LE,RO]{\textsl{\rightmark}}
\fancyhead[LO,RE]{\textsl{\leftmark}}
\fancyfoot[C]{\thepage}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\end{verbatim}
We use the following additional page style \texttt{myfancy}. It just puts ``MYFANCY SECTION'' instead of the section title:
\begin{verbatim}
\fancypagestyle{myfancy}{
\fancyhead[LE,RO]{MYFANCY SECTION}
% The rest is inherited from fancy
}
\end{verbatim}
\end{boxedminipage}
\chapter{Just \cs{thispagestyle}}
\label{ch:just-thispagestyle}
\thispagestyle{myfancy}
\begin{boxedminipage}{\textwidth}
Here we start with a \verb|\thispagestyle{myfancy}|. The header on this page comes out as\\
on the left: \textsl{Just \cs{thispagestyle}} (=the normal header)\\
on the right: MYFANCY SECTION
The next page will have a more traditional header with chapter and section titles.
The \verb|\thispagestyle{myfancy}| works here, because it is given right at the beginning of the chapter where we are sure that a page break will not occur.
\end{boxedminipage}
\bigskip
\lipsum[1-3]
\lipsum[3-5]
\newpage
\section{A wrong \cs{thispagestyle} attempt}
\begin{boxedminipage}{\textwidth}
In this section we will put a \verb|\thispagestyle{myfancy}| in the middle of the text. But it appears that this text is close to the end of the page. So in this case \TeX{} is still on the current page when it is processing the \verb|\thispagestyle{myfancy}| command. However, during the page breaking \TeX{} decides that the text will not fit on the page and moves it to the next page. So the text that contains the \verb|\thispagestyle{myfancy}| ends up at the next page. That means \textbf{the next page should have gotten the myfancy header}, but the current page actually gets it. \textbf{Now the different header is no longer at the page where it says it should be.}
\end{boxedminipage}
\bigskip
\lipsum[6-8]
\bigskip
Suspendisse vel felis. Ut lorem lorem, interdum eu, tincidunt sit amet, laoreet vitae, arcu. Aenean faucibus pede eu ante. Praesent enim elit, rutrum at, molestie non, nonummy vel, nisl. Ut lectus eros, malesuada sit amet, fer- mentum eu, sodales cursus, magna. Donec eu purus. Quisque vehicula, urna sed ultricies auctor, pede lorem egestas dui, et convallis elit erat sed nulla. Donec luctus. Curabitur et nunc. Aliquam dolor odio, commodo pretium, ultricies non, pharetra in, velit. Integer arcu est, nonummy in, fermentum faucibus, egestas vel, odio.
\bigskip
\noindent
\begin{boxedminipage}{\textwidth}
\textbf{This page was supposed have a MYFANCY SECTION header.
\thispagestyle{myfancy}
It is done with the} \verb|\thispagestyle{myfancy}| \textbf{command right at this place.
However, it appears that the MYFANCY SECTION header comes on the previous page.}
\end{boxedminipage}
\bigskip
\lipsum[8-9]
\newpage
\chapter{A better solution}
\label{ch:pageref}
\pagestyle{switch}
\begin{boxedminipage}{\textwidth}
This is example 25~(a).
In this chapter we use a better solution to the \verb|\thispagestyle{myfancy}| in the middle of the text.
For selecting a different page style for the page where a specific text appears we put a label \texttt{otherpagestyle} in the text and then use a definition in the header that chooses
If the page number is equal to the page number of the label we use the same as \verb|\pagestyle{myfancy}|, otherwise the default values of \verb|\pagestyle{fancy}|.
\begin{verbatim}
\fancypagestyle{switch}{
\fancyhead[LE,RO]{%
\ifthenelse{\value{page}=\getpagerefnumber{otherpagestyle}}
{MYFANCY SECTION}
{\textsl{\rightmark}}}
% The rest is inherited from fancy
}
\end{verbatim}
\end{boxedminipage}
\bigskip
\lipsum[6-8]
\bigskip
Suspendisse vel felis. Ut lorem lorem, interdum eu, tincidunt sit amet, laoreet vitae, arcu. Aenean faucibus pede eu ante. Praesent enim elit, rutrum at, molestie non, nonummy vel, nisl. Ut lectus eros, malesuada sit amet, fer- mentum eu, sodales cursus, magna. Donec eu purus. Quisque vehicula, urna sed ultricies auctor, pede lorem egestas dui, et convallis elit erat sed nulla. Donec luctus. Curabitur et nunc.
\section{Here it comes}
\noindent
\begin{boxedminipage}{\textwidth}
\begin{minipage}{\linewidth}
\textbf{This page should have a different header than the surrounding
pages. The header should contain \textnormal{``MYFANCY SECTION''}.
\label{otherpagestyle}
It is done with the} \verb|\pagestyle{switch}| \textbf{command, that
has tests in the header field definitions. This chooses the actual
header depending on the page number.}
\end{minipage}
\end{boxedminipage}
\bigskip
\lipsum[8-10]
\medskip
\noindent
\begin{boxedminipage}{\textwidth}
\textbf{This page should get the normal header again because the page number is different from the page number in the label.}
\end{boxedminipage}
\chapter{Showstruts}
\label{ch:showstruts}
\pagestyle{showstruts}
\begin{boxedminipage}{\textwidth}
This is example 25~(b) from the \textsf{fancyhdr} documentation. It uses the same principle as the previous chapter to get a different header on one particular page.
Only the page style is now \texttt{showstruts} and also the label is called \texttt{showstruts}.
We start the \verb|\pagestyle{showstruts}| right here at the beginning of the chapter.
Here is the code:
\begin{verbatim}
\newcommand{\strutheader}{%
\texttt{\textbackslash strut}:
\rule[-0.3\normalbaselineskip]{10pt}{0.3\normalbaselineskip}%
\rule{10pt}{0.7\normalbaselineskip}
\texttt{\textbackslash headruleskip}$\searrow$
\raisebox{-0.3\normalbaselineskip}[0pt][0pt]%
{\ifdim \headruleskip>0pt
\rule[-\headruleskip]{10pt}{\headruleskip}
\else
\rule{10pt}{-\headruleskip}
\fi}
}
\newcommand{\strutfooter}{%
\raisebox{0pt}[0pt][0pt]{%
\texttt{\textbackslash strut}:
\rule[-0.3\normalbaselineskip]{10pt}{0.3\normalbaselineskip}%
\rule{10pt}{0.7\normalbaselineskip}
\texttt{\textbackslash footruleskip} $\nearrow$
\rule[0.7\normalbaselineskip]{10pt}{\footruleskip}}%
}
\end{verbatim}
\end{boxedminipage}
\noindent
\begin{boxedminipage}{\textwidth}
\begin{verbatim}
\fancypagestyle{showstruts}{%
\fancyhead[L]{%
\ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
{\strutheader}%
{\rightmark}%
}
\fancyfoot[L]{%
\ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
{\strutfooter}%
{}%
}
\fancyheadinit{%
\ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
{\renewcommand{\headruleskip}{4pt}}%
{\renewcommand{\headruleskip}{0pt}}%
}
\fancyfootinit{%
\ifthenelse{\value{page}=\getpagerefnumber{showstruts}}%
{\renewcommand{\footrulewidth}{0.4pt}}%
{\renewcommand{\footrulewidth}{0pt}}%
}
}
\end{verbatim}
\end{boxedminipage}
\section{Here we go}
\lipsum[1-3]
\medskip
\noindent
\begin{boxedminipage}{\textwidth}
\textbf{Here we put the label \texttt{showstruts}, so the struts in the header and footer should appear on this page.}
\label{showstruts}
\end{boxedminipage}%
\nopagebreak
% Set the \verb|\headheight| to accomodate the larger \texttt{showstruts} header
\setlength{\headheight}{16pt}%
\addtolength{\topmargin}{-4.0pt}
\medskip
\lipsum[3-5]
\end{document}