-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-switchpagestyle.tex
267 lines (220 loc) · 7.91 KB
/
test-switchpagestyle.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
\documentclass[openany]{book}
\usepackage{lipsum}
\usepackage{boxedminipage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\fancypagestyle{myfancy}{
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ ##1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ ##1}}
}
\fancypagestyle{myotherfancy}{
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ ##1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ ##1}}
\fancyhf{}
\fancyhead[LE]{\textbf{\rightmark}}
\fancyhead[RO]{\textbf{\leftmark}}
\fancyfoot[C]{\textbf{\thepage}}
}
\begin{document}
\tableofcontents
\newpage
\thispagestyle{plain}
\noindent
\begin{boxedminipage}{\textwidth}
This is test-switchpagestyle.tex
It demonstrates switching between page styles based on
\texttt{fancyhdr} in the \texttt{book} class. We are switching between
four page styles:\\ The standard \LaTeX{} page style \texttt{headings},
our page style \texttt{fancy}, and two \texttt{fancyhdr}-based styles
\texttt{myfancy} and \texttt{myotherfancy}, defined with
\verb|\fancypagestyle|. And chapter opening pages use page style \texttt{plain}.
Here are the definitions:
\begin{verbatim}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\fancypagestyle{myfancy}{
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ ##1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ ##1}}
}
\fancypagestyle{myotherfancy}{
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ ##1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ ##1}}
\fancyhf{}
\fancyhead[LE]{\textbf{\rightmark}}
\fancyhead[RO]{\textbf{\leftmark}}
\fancyfoot[C]{\textbf{\thepage}}
}
\end{verbatim}
\end{boxedminipage}
\chapter{Introduction}
\noindent
\begin{boxedminipage}{\textwidth}
We start with page style \texttt{fancy} with the following headers:
\begin{verbatim}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ ##1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ ##1}}
\end{verbatim}
%
Chapter pages: just page style \texttt{plain}.
\\
Even page, left:
\begin{quote}
\textsl{1.1. The Problem} (= section number. section title)
\end{quote}
Even page, right:
\begin{quote}
\textsl{1. Introduction} (= chapter number. chapter title)
\end{quote}
On odd pages it is mirrored, probably with a different section.
These come out as \textsl{slanted}, because that is the default for page style \texttt{fancy}.
The page number comes on the footer.
\end{boxedminipage}
\bigskip
\lipsum[1]
\newpage
\section{The Problem}
\label{sec:problem}
\lipsum[2-3]
\section{Evaluation}
\lipsum[3-5]
\lipsum[6]
\newpage
\pagestyle{headings}
\chapter{Second chapter}
\noindent
\begin{boxedminipage}{\textwidth}
In this chapter we have switched to the standard page style \texttt{headings}. The marks are different than in page style fancy. For example, they are in uppercase.
{\bfseries Please note that because page style \texttt{headings} uses a different \verb|\chaptermark| than page style \texttt{fancy}, the switching of the page style must be done before the \verb|\chapter| command, and it must be preceded by a \verb|\newpage|, and this is also necessary in the following chapters.}
\begin{verbatim}
\newpage
\pagestyle{headings}
\chapter{Second chapter}
\end{verbatim}
The headers should come out as:
\\
Chapter pages: just page style \texttt{plain}.
\\
Right header on even page:
\begin{quote}
\textsl{CHAPTER 2. SECOND CHAPTER}
\end{quote}
Left header on odd page:
\begin{quote}
\textsl{2.1. ANOTHER SECTION}
\end{quote}
These come out as \textsl{slanted}, because that is the default for page style \texttt{fancy}.
The page number comes on the other side of the header, not slanted.
\end{boxedminipage}
\bigskip
\lipsum[1]
\section{Another section}
\lipsum
\newpage
\pagestyle{fancy}
\chapter{Third chapter}
\noindent
\begin{boxedminipage}{\textwidth}
Here we switch back to page style \texttt{fancy}.
But we see that we still get the marks as defined in the page style \texttt{headings}.
This is because the definitions of the marks are not part of page style \texttt{fancy}, but they are global in the document.
However, in this case we still have the definitions of \verb|\fancyhead| of \verb|\pagestyle{fancy}|, because we used the standard page style \texttt{headings}, which does not use \verb|\fancyhead|. So we get a mixture of the two page styles. If we would have used the \texttt{fancyhdr} version of page style \texttt{headings}, we would get exactly the same as in the previous chapter. See the file \texttt{test-switch-our-headings.tex}.
The headers should come out as:
\\
Chapter pages: just page style \texttt{plain}.
\\
Right header on even page:
\begin{quote}
\textsl{CHAPTER 3. THIRD CHAPTER}
\end{quote}
Left header on even page:
\begin{quote}
\textsl{3.1. YA SECTION}
\end{quote}
On odd pages it is mirrored.
These come out as \textsl{slanted}, because that is the default for page style \texttt{fancy}.
The page number comes on the footer, not slanted.
\end{boxedminipage}
\bigskip
\lipsum[1]
\section{YA section}
\lipsum
\newpage
\pagestyle{myfancy}
\chapter{Fourth chapter}
\noindent
\begin{boxedminipage}{\textwidth}
Here we switch to page style \texttt{myfancy}.
Now we see that we get the marks as defined in the definition of page style \texttt{myfancy}.
This is because the definitions of the marks are part of that definition.
\begin{verbatim}
\fancypagestyle{myfancy}{
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ ##1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ ##1}}
}
\end{verbatim}
However, the layout of the headers and footers is not defined in page style \texttt{myfancy}. Therefore we get the layout inherited from page style \texttt{fancy}.
But because of our own marks, the contents of the headers are not in uppercase, and the word 'CHAPTER' is not present.
The headers should come out as:
\\
Chapter pages: just page style \texttt{plain}.
\\
Even page, left:
\begin{quote}
\textsl{4.1. YAno section}
\end{quote}
Even page, right:
\begin{quote}
\textsl{4. Fourth chapter}
\end{quote}
On odd pages it is mirrored.
These come out as \textsl{slanted}, because that is the default for page style \texttt{fancy} and is inherited by page style \texttt{myfancy}.
The page number comes on the footer.
Please note that the definition of \texttt{myfancy} does not include \verb|\fancyhead|. So it picks up whatever is current when it is invoked. It is generally better to include these definition, however.
\end{boxedminipage}
\bigskip
\lipsum[1]
\section{YAno section}
\lipsum
\newpage
\pagestyle{myotherfancy}
\chapter{Fifth chapter}
\noindent
\begin{boxedminipage}{\textwidth}
Here we switch to page style \texttt{myotherfancy}.
Now we see that we get the marks as defined in the definition of page style \texttt{myotherfancy}.
This is because the definitions of the marks are part of that definition.
\begin{verbatim}
\fancypagestyle{myotherfancy}{
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ ##1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ ##1}}
\fancyhf{}
\fancyhead[LE]{\textbf{\rightmark}}
\fancyhead[RO]{\textbf{\leftmark}}
\fancyfoot[C]{\textbf{\thepage}}
}
\end{verbatim}
And also, the layout of the headers and footers is defined in this page style. It defines the headers and footers \textbf{bold} instead of slanted.
The contents of the headers are not in uppercase, and the word 'CHAPTER' is not present.
The headers should come out as:
\\
Chapter pages: just page style \texttt{plain}.
\\
Right header on odd page:
\begin{quote}
\textbf{5. Fifth chapter}
\end{quote}
Left header on even page:
\begin{quote}
\textbf{5.1. YAno section}
\end{quote}
The page number comes on the footer.
These come out as \textbf{bold}.
\end{boxedminipage}
\bigskip
\lipsum[1]
\section{YAno section}
\lipsum
\end{document}