| 1 |
% |
| 2 |
% Copyright (C) 1998-2025 Javier Bezos http://www.texnia.com |
| 3 |
% |
| 4 |
% This file may be distributed and/or modified under the conditions of |
| 5 |
% the MIT License. A version can be found at the end of this file. |
| 6 |
% |
| 7 |
% Repository: https://github.com/jbezos/titlesec |
| 8 |
% |
| 9 |
|
| 10 |
\def\fileversion{2.17} |
| 11 |
\def\docdate{2025/01/04} |
| 12 |
|
| 13 |
\documentclass[a4paper]{ltxguide} |
| 14 |
\usepackage[sf,bf,compact,topmarks,calcwidth,pagestyles]{titlesec} |
| 15 |
\usepackage{titletoc} |
| 16 |
\def\gobble#1{} |
| 17 |
\DeclareRobustCommand\cs[1]{\expandafter\gobble\string\\#1} |
| 18 |
\makeatletter |
| 19 |
\newenvironment{desc} |
| 20 |
{\if@nobreak |
| 21 |
\vskip-\lastskip |
| 22 |
\vspace*{-2.5ex}% |
| 23 |
\fi |
| 24 |
\decl} |
| 25 |
{\enddecl} |
| 26 |
\makeatother |
| 27 |
|
| 28 |
\usepackage{textcomp,pslatex} |
| 29 |
\usepackage[linktocpage]{hyperref} |
| 30 |
|
| 31 |
\title{Headers and footers with \textsf{titleps}\footnote{The |
| 32 |
\textsf{titleps} package is currently at version \fileversion. |
| 33 |
\copyright{} 2016 Javier Bezos. All Rights Reserved.}} |
| 34 |
|
| 35 |
\author{Javier Bezos\footnote{For bug reports, comments and |
| 36 |
suggestions go to \href{http://www.texnia.com/contact.html}% |
| 37 |
{\texttt{http://www.texnia.com/contact.html}}. English |
| 38 |
is not my strong point, so contact me when you find mistakes in the |
| 39 |
manual. Other packages by the same author: \textsf{gloss} (with |
| 40 |
Jos\'e Luis D\'{\i}az), \textsf{enumitem, accents, tensind, esindex, |
| 41 |
dotlessi}.}} |
| 42 |
|
| 43 |
\date{\docdate} |
| 44 |
|
| 45 |
\widenhead{2.1pc}{0pc} |
| 46 |
\titlelabel{\thetitle.\quad} |
| 47 |
|
| 48 |
\renewpagestyle{plain}[\small\sffamily\slshape]{ |
| 49 |
\footrule |
| 50 |
\setfoot{}{\thepage}{}} |
| 51 |
|
| 52 |
\newpagestyle{myps}[\small\sffamily\slshape]{ |
| 53 |
\headrule |
| 54 |
\sethead{titlesec -- titleps}{\sectiontitle}{\thepage}} |
| 55 |
|
| 56 |
\pagestyle{myps} |
| 57 |
|
| 58 |
\newcommand{\examplesep}{% |
| 59 |
\begin{center}% |
| 60 |
\rule{4pt}{4pt}% |
| 61 |
\end{center}} |
| 62 |
|
| 63 |
\contentsmargin{0pt} |
| 64 |
|
| 65 |
\titlecontents*{section}[0pt]%[1.8pc] |
| 66 |
{} |
| 67 |
{\thecontentslabel. } |
| 68 |
{} |
| 69 |
{, \thecontentspage} |
| 70 |
[. --- ][.] |
| 71 |
|
| 72 |
\addtolength{\topmargin}{-3pc} |
| 73 |
\addtolength{\textwidth}{6pc} |
| 74 |
\addtolength{\oddsidemargin}{-2pc} |
| 75 |
\addtolength{\textheight}{7pc} |
| 76 |
|
| 77 |
\raggedright |
| 78 |
\parindent1em |
| 79 |
\parskip0pt |
| 80 |
|
| 81 |
\begin{document} |
| 82 |
|
| 83 |
\maketitle |
| 84 |
\tableofcontents |
| 85 |
\section{Introduction} |
| 86 |
|
| 87 |
The \textsf{titleps} package provides tools for one-stage setting of |
| 88 |
page styles (headlines and footlines). A higher-level interface is |
| 89 |
used, where the mark mechanism is hidden and there is no need to deal |
| 90 |
with |\leftmark|s and |\rightmark|s -- just use a command or variable |
| 91 |
registered as a ``mark'' as the expected value will be returned, i.e., |
| 92 |
those when the mark was emitted, either by a sectioning command or |
| 93 |
explicitly with |\chaptermark|, |\sectionmark|, etc. A simple |
| 94 |
example, whose meaning should be obvious, is: |
| 95 |
\begin{verbatim} |
| 96 |
\newpagestyle{main}{ |
| 97 |
\sethead[\thepage][\chaptertitle][(\thesection] % even |
| 98 |
{\thesection)}{\sectiontitle}{\thepage}} % odd |
| 99 |
\pagestyle{main} |
| 100 |
\end{verbatim} |
| 101 |
|
| 102 |
Other features are: |
| 103 |
\begin{itemize} |
| 104 |
\item Working top marks, compatible with floats (unlike the standard |
| 105 |
|\topmark|, which does not work correctly in \LaTeX{}). |
| 106 |
\item Access to top, first and botttom marks in a single headline/footline |
| 107 |
(e.g., the first and last section numbers). |
| 108 |
\item Marks for more than 2 sectioning levels. |
| 109 |
\item Auto-defining of suitable |\sectionmark| and the like. |
| 110 |
\item Simple (and not so simple) headrules and footrules. |
| 111 |
\item Headlines and footlines for pages with floats. |
| 112 |
\item Headlines and footlines for specific floats (a sort of |
| 113 |
|\thispagestyle| for floats). |
| 114 |
\item Multiple sets of marks (named here \emph{markset}s and |
| 115 |
\textit{extra marks}). |
| 116 |
\end{itemize} |
| 117 |
|
| 118 |
It can be used without \textsf{titlesec}, but you will get most of |
| 119 |
it when used together. To load it as a separate package, use the |
| 120 |
customary \verb|\usepackage{titleps}|, but with \textsf{titlesec} you |
| 121 |
have to load it with: |
| 122 |
\begin{verbatim} |
| 123 |
\usepackage[pagestyles]{titlesec} |
| 124 |
\end{verbatim} |
| 125 |
|
| 126 |
Specific tools for sectioning command marks are provided, which are |
| 127 |
considered the main \textit{markset} (unnamed) and carry out some |
| 128 |
internal task. However, \textsf{titleps} can be used as well for |
| 129 |
headers with the first an last entry of a page in a dictionary or index, |
| 130 |
for example, thank to the \textit{extra marks} described below. |
| 131 |
|
| 132 |
It works with standard classes and many others; however, additional |
| 133 |
\LaTeX{} layout adjustments could be necessary in some of them (for |
| 134 |
instance the \textsc{AMS} classes) and several packages emitting marks |
| 135 |
directly with \verb|\markboth| and \verb|\markleft|.\footnote{% |
| 136 |
Two columns layout requires the \textsf{fix2col} package by David |
| 137 |
Carlisle.} |
| 138 |
|
| 139 |
Once loaded the package, you can define your own page styles and then |
| 140 |
activate them, but note page styles so defined cannot be used with |
| 141 |
\verb|\thispagestyle| except if the surrounding page style has been |
| 142 |
defined with \textsf{titleps}, too. |
| 143 |
|
| 144 |
%%%% empty ? plain ? |
| 145 |
|
| 146 |
\section{Defining Page Styles} |
| 147 |
|
| 148 |
\begin{desc} |
| 149 |
|\newpagestyle{<name>}[<global-style>]{<commands>}|\\ |
| 150 |
|\renewpagestyle{<name>}[<global-style>]{<commands>}| |
| 151 |
\end{desc} |
| 152 |
|
| 153 |
Defines a new style or redefines an existing one, named |<name>|. For |
| 154 |
convenience, spaces and end of lines are ignored, and you need not |
| 155 |
``hide'' them with |%|.\footnote{Even if marks should be reserved |
| 156 |
to pass information |
| 157 |
to headers, some classes, like the AMS ones, introduce additional |
| 158 |
code. When redefining the |plain| style of AMS classes, you must add |
| 159 |
the following line: |\cs{global}\cs{topskip}\cs{normaltopskip}|.} |
| 160 |
|
| 161 |
|<global-style>| is any command to be applied to both footlines and |
| 162 |
headlines. Fragile commands are allowed. |
| 163 |
|
| 164 |
In |<commands>| you can use: |
| 165 |
|
| 166 |
|
| 167 |
\begin{desc} |
| 168 |
|\sethead[<even-left>][<even-center>][<even-right>]|\\ |
| 169 |
| {<odd-left>}{<odd-center>}{<odd-right>}|\\ |
| 170 |
|\setfoot[<even-left>][<even-center>][<even-right>]|\\ |
| 171 |
| {<odd-left>}{<odd-center>}{<odd-right>}| |
| 172 |
\end{desc} |
| 173 |
|
| 174 |
Set the corresponding part in headlines and footlines (note the |
| 175 |
``visual'' layout of parameters). The optional arguments are the |
| 176 |
three or none. If no optional arguments are given the odd-page |
| 177 |
settings applies to both even and odd pages. A couple of starred |
| 178 |
variant (|\setfoot*|, |\sethead*|) reverses the order of the settings |
| 179 |
for even pages (obviously, with them the optional arguments are not |
| 180 |
allowed). If |\sethead| is not given, then the headline it is left |
| 181 |
empty, and same for |\setfoot| and the footline. |
| 182 |
|
| 183 |
In the arguments of |\sethead|/|\setfoot| and because of its one-stage |
| 184 |
mechanism, we must distinguish between two groups of commands: |
| 185 |
\begin{itemize} |
| 186 |
\item The first one includes those saved when the marks are emitted, |
| 187 |
with information related to sections, and includes: |
| 188 |
\begin{itemize} |
| 189 |
\item |\thechapter|, |\thesection|, |\thesubsection|\dots{} |
| 190 |
\item |\chaptertitle|, |\sectiontitle|, |\subsectiontitle|\dots{} which print the |
| 191 |
chapter, section\dots{} title. |
| 192 |
\item (Only \textsf{titlesec}. Not in \textsf{titleps}.) |
| 193 |
|\ifthechapter{<true>}{<false>}|, |\ifthesection{<true>}{<false>}|, |
| 194 |
|\ifthesubsection{<true>}{<false>}|\dots{} which expands to |<true>| |
| 195 |
except if the corresponding title lacks of label or there is no title |
| 196 |
yet after the superior level (for example, between |\chapter| and a |
| 197 |
subsequent |\section|). |
| 198 |
\item Any other command or value ``registered'' as ``mark.'' (See below.) |
| 199 |
\end{itemize} |
| 200 |
They are ordinary commands, with no internal marks at all, and you can |
| 201 |
test if, for example, they are empty. |
| 202 |
|
| 203 |
\item The second group are those expanded on every page, and includes: |
| 204 |
\begin{itemize} |
| 205 |
\item |\thepage|. |
| 206 |
\item Any other command not included in the previous items. |
| 207 |
\end{itemize} |
| 208 |
\end{itemize} |
| 209 |
|
| 210 |
\begin{desc} |
| 211 |
|\settitlemarks{<level-name>,<sublevel-name>,<subsublevel-name>...}|\\ |
| 212 |
|\settitlemarks*{<level-name>,<sublevel-name>,<subsublevel-name>...}| |
| 213 |
\end{desc} |
| 214 |
Sets which |\...title| commands are to be defined, and when the marks |
| 215 |
are emitted; any number of levels is allowed (1, 2, 3...). For example |
| 216 |
|\settitlemarks{chapter,section}| |
| 217 |
means that: |
| 218 |
\begin{itemize} |
| 219 |
\item |\chaptertitle| and |\sectiontitle| are the allowed titles in |
| 220 |
headlines, |
| 221 |
\item |\sectiontitle| is reset in |\chapter|, |
| 222 |
\item (Only \textsf{titlesec}. Not in \textsf{titleps}.) |
| 223 |
|\ifthechapter| and |\ifthesection| are valid tests. |
| 224 |
\item Marks are updated in |\chapter| and |\section|. |
| 225 |
\end{itemize} |
| 226 |
Default is |\settitlemarks{chapter,section}|, but |
| 227 |
|\settitlemarks{section,subsection}| in \textsf{article} class. |
| 228 |
|\settitlemarks| may be used outside |\(re)newpagestyle| to set the |
| 229 |
default to be used in newly defined and redefined page styles -- it is |
| 230 |
used in |\pagestyle|.\footnote{The command \texttt{\string\setmarks} is |
| 231 |
deprecated. Now |
| 232 |
\texttt{\string\setmarks\string{<primary>\string}\string{<secondary>\string}}is |
| 233 |
\texttt{\string\settitlemarks\allowbreak\string{<primary>,\allowbreak<secundary>\string}}.} |
| 234 |
|
| 235 |
The starred version |\settitlemarks*| creates parallel extra marks |
| 236 |
as described below. |
| 237 |
|
| 238 |
\begin{desc} |
| 239 |
|\headrule \footrule|\\ |
| 240 |
|\setheadrule{<length>} \setfootrule{<length>}| |
| 241 |
\end{desc} |
| 242 |
|
| 243 |
If you want a rule below the headline and above the footline. You may |
| 244 |
also set their width directly with the commands |\setheadrule| and |
| 245 |
|\setfootrule|. (For instance, |\setheadrule{.4pt}| which is, by the |
| 246 |
way, the default value.) |
| 247 |
|
| 248 |
These commands are local to a page style, i.e., defining them directly |
| 249 |
in the preamble will not work because the page style settings will |
| 250 |
override them. |
| 251 |
|
| 252 |
\begin{desc} |
| 253 |
|\makeheadrule \makefootrule| |
| 254 |
\end{desc} |
| 255 |
|
| 256 |
These commands are used by \textsf{titleps} to typeset the rules. |
| 257 |
If there is no rule, both commands are empty (this value is the |
| 258 |
default). |
| 259 |
|\setheadrule{|\emph{dim}|}| just stands for |
| 260 |
\begin{verbatim} |
| 261 |
\renewcommand{\makeheadrule}{\rule[-.3\baselineskip]{\linewidth}{<dim>}} |
| 262 |
\end{verbatim} |
| 263 |
unless if \emph{dim} is 0 pt, which empties |
| 264 |
|\makeheadrule| (and similarly |\setfootrule|). |
| 265 |
|
| 266 |
You can access the total header/footer width with |\linewidth| |
| 267 |
but the box enclosing the rule is in fact dimensionless. Hence, |
| 268 |
you must be concerned with the rule placement only. Its |
| 269 |
baseline is the same as that of the header/footer. That means the |
| 270 |
material to be used as rule should be raised or lowered with |
| 271 |
|\raisebox|, the lifting argument in |\rule| or by using sensible |
| 272 |
coordinates in |picture|, for instance. That makes easy to |
| 273 |
place material above \emph{and} below. For instance, |
| 274 |
the following code creates a headline with a black bold line |
| 275 |
above and a red rule below (the \textsf{color} package is required): |
| 276 |
\begin{verbatim} |
| 277 |
\renewcommand{\makeheadrule}{% |
| 278 |
\makebox[0pt][l]{\rule[.7\baselineskip]{\linewidth}{0.8pt}}% |
| 279 |
\color[named]{Red}% |
| 280 |
\rule[-.3\baselineskip]{\linewidth}{0.4pt}} |
| 281 |
\end{verbatim} |
| 282 |
|
| 283 |
Of course, the material to be used as rule is not restricted to actual |
| 284 |
rules; pictures and leaders, for instance, are allowed, too. |
| 285 |
|
| 286 |
\section{On \texttt{\cs{markboth}} and \texttt{\cs{markleft}}} |
| 287 |
|
| 288 |
As \textit{The \LaTeX{} Companion explains} ``Leslie Lamport had a |
| 289 |
specific marking scheme in mind when he designed those |
| 290 |
commands''. They are clearly intended for the \verb|heading| and |
| 291 |
\verb|myheading| pagestyles, with a \textit{main-mark} on the left |
| 292 |
page and a \textit{sub-mark} on the right one. |
| 293 |
|
| 294 |
In order to provide the functionality offered by \textsf{titleps}, a |
| 295 |
more general, less specific mechanism is devised, which means |
| 296 |
|\markboth| here does not make sense, because it doesn't work like in |
| 297 |
standard \LaTeX, and in fact, can lead to unpredictable results. |
| 298 |
|
| 299 |
Therefore, using directly the marking commands is discouraged (see |
| 300 |
|titlesec.pdf|), but if you need them, you may write: |
| 301 |
\begin{verbatim} |
| 302 |
\chapter*{My Chapter} |
| 303 |
\chaptermark{My Chapter} |
| 304 |
\end{verbatim} |
| 305 |
|
| 306 |
But some issues remain, because there are a number of packages |
| 307 |
assuming the pagestyle is \verb|heading| or \verb|myheading|. This is, |
| 308 |
of course, a reasonable guess, but not always correct (even if |
| 309 |
\textsf{titleps} is not used at all). Most of them do the right thing |
| 310 |
-- \verb|\markboth| is encapsulated into a macro easily redefinable so |
| 311 |
that the user can modify it if necessary. This is true, for example, |
| 312 |
for \textsf{biblatex}, but unfortunately not for \textsf{endnotes}. |
| 313 |
When this happens, you can resort to the following macro. |
| 314 |
|
| 315 |
\begin{desc} |
| 316 |
|\setmarkboth{<code-to-use>}| |
| 317 |
\end{desc} |
| 318 |
|
| 319 |
From this point on, \verb|\markboth| behaves as defined. It doesn't |
| 320 |
redefine directly the command, but rather provides a replacement code |
| 321 |
(you can use |#1| and |#2| for the two arguments). With |
| 322 |
|\resetmarkboth| (which can be used inside |\setmarkboth|) the |
| 323 |
original definition will be again in force. For example, to cancel the |
| 324 |
next |\markboth|: |
| 325 |
\begin{verbatim} |
| 326 |
\setmarkboth{\resetmarkboth\markboth{}{}} |
| 327 |
\end{verbatim} |
| 328 |
|
| 329 |
\section{Headline/footline width} |
| 330 |
|
| 331 |
\begin{desc} |
| 332 |
|\widenhead[<even-left>][<even-right>]{<odd-left>}{<odd-right>}|\\ |
| 333 |
|\widenhead*{<even-right/odd-left>}{<even-left/odd-right>}| |
| 334 |
\end{desc} |
| 335 |
|
| 336 |
Makes the headlines/footlines lines wider. The extra width is |
| 337 |
asymmetrically added and hence the two [four] arguments. Like |
| 338 |
|\sethead|, the starred version reverses the setting for even |
| 339 |
pages---for example, |\widenhead*{0pt}{6pc}| is the same as |
| 340 |
|\widenhead[6pc][0pt]{0pt}{6pc}|. |
| 341 |
|
| 342 |
To be used outside |\(re)newpagestyle|. |
| 343 |
|
| 344 |
\begin{desc} |
| 345 |
|nopatches| \qquad (package option) |
| 346 |
\end{desc} |
| 347 |
|
| 348 |
By default, sectioning commands are patched slightly for top marks |
| 349 |
and |\@mkboth| to work, so that page styles behave like standard |
| 350 |
|headings|. However, if you want to be explicit, like with standard |
| 351 |
|myheadings|, and emit premarks and, if necessary, marks by yourself, |
| 352 |
set this package option. Remenber you have to use |\sectionmark| and |
| 353 |
the like, and not |\markboth| or |\markright|. |
| 354 |
|
| 355 |
You might also prefer to patch the sectioning commands by yourself, |
| 356 |
either with low-level definitions or with the provided |
| 357 |
|\TitlepsPatchSection| (with a starred version which adds no premark |
| 358 |
and intended mainly for chapters). For example: |
| 359 |
\begin{verbatim} |
| 360 |
\TitlepsPatchSection*{chapter} % patches \chapter |
| 361 |
\TitlepsPatchSection{section} % patches \section |
| 362 |
\end{verbatim} |
| 363 |
(In standard classes |\part| emits no mark, and therefore it is not |
| 364 |
patched by default.) |
| 365 |
|
| 366 |
\section{Marks} |
| 367 |
|
| 368 |
Marks can be retrieved in 4 ways: |
| 369 |
\begin{description} |
| 370 |
\item[top marks] If a page begins with text, they are the marks |
| 371 |
belonging to the sectioning unit of that text. If a page begin with a |
| 372 |
sectioning title, they are the marks of that title. In other words, |
| 373 |
top marks refer to the section immediately adjacent to the |
| 374 |
headline. |
| 375 |
\item[first marks] The marks of the very first sectioning title. |
| 376 |
\item[botttom marks] The marks of the very last (bottom) sectioning |
| 377 |
title (also known as \textit{bot marks}). |
| 378 |
\item[next top marks] A botttom mark with the values of the top mark of |
| 379 |
the next page (only |straight| class or equivalent); by picking some |
| 380 |
value from it and comparing it with the corresponding value from the |
| 381 |
botttom marks you may know if a section continues in the next page. |
| 382 |
Of course, it will not be used very often. |
| 383 |
\end{description} |
| 384 |
Standard \LaTeX{} provides only first and bottom marks. As you see, with |
| 385 |
\textsf{titleps} you have two additional marks, namely, top and next |
| 386 |
top marks. |
| 387 |
|
| 388 |
It should be stressed top marks are not the same as the primitive |
| 389 |
\verb|\topmark| (which, in fact, is not used internally at all). They |
| 390 |
are true top marks, returning the expected result when the title is at |
| 391 |
the top of the page. Further, they are compatible with floats, which |
| 392 |
is not true with \verb|\topmark|s. However, they fail with explicit |
| 393 |
page breaks, but you can use \verb|\pretitlemark| as described |
| 394 |
below. |
| 395 |
|
| 396 |
\begin{desc} |
| 397 |
|outermarks innermarks topmarks botmarks| \qquad (package options) |
| 398 |
\end{desc} |
| 399 |
|
| 400 |
|innermarks| is the default in \LaTeX, with bottom marks in even pages |
| 401 |
and first marks in odd pages. More convenient is |outermarks|, with |
| 402 |
top marks in even pages and bottom marks in odd pages; it is the more |
| 403 |
usual system in classic scientific literature and it is described in |
| 404 |
\textit{The \TeX{}book}, p.~259.\footnote{|outermarks| may not work |
| 405 |
well in conjunction with explicit |\string\<section>mark| commands} Both of them are intended for two side printing; |
| 406 |
|topmarks|/|botmarks| are intended for one side printing with top/bot |
| 407 |
marks in every page (they can be used in two side printing as well). |
| 408 |
|
| 409 |
\begin{desc} |
| 410 |
|\bottitlemarks \toptitlemarks \firsttitlemarks \nexttoptitlemarks|\\ |
| 411 |
|\outertitlemarks \innertitlemarks| |
| 412 |
\end{desc} |
| 413 |
|
| 414 |
These commands set which mark the values of the subsequent |
| 415 |
|\thesection|, |\sectiontitle|, etc., will be taken from. |
| 416 |
These macros are switches, and therefore subsequent commands and |
| 417 |
variables are taken from the selected mark. The following is valid: |
| 418 |
\begin{verbatim} |
| 419 |
\toptitlemarks\textbf{\thesection.} \sectiontitle -- |
| 420 |
\bottitlemarks\textbf{\thesection.} \sectiontitle |
| 421 |
\end{verbatim} |
| 422 |
|
| 423 |
You can use them freely in your headers;\,% |
| 424 |
\footnote{Not exactly: top marks must not be used in the page where a |
| 425 |
chapter begins, except by overriding the default definition and making |
| 426 |
it of |top| class.} just for fun, the following header shows the |
| 427 |
section label from three of these marks: |
| 428 |
\begin{verbatim} |
| 429 |
\newpagestyle{funny}{ |
| 430 |
\sethead{\toptitlemarks Top is \thesection} |
| 431 |
{\firsttitlemarks First is \thesection} |
| 432 |
{\bottitlemarks Bot is \thesection}} |
| 433 |
\end{verbatim} |
| 434 |
|
| 435 |
In multilingual documents, the language in force is that corresponding |
| 436 |
to the package options -- command versions does not switch the |
| 437 |
language, but you can do it easily with the help a new title mark and |
| 438 |
then switching the language, as explained below. |
| 439 |
|
| 440 |
\begin{desc} |
| 441 |
|\newtitlemark{<command-name>}|\\ |
| 442 |
|\newtitlemark*{<variable-name>}| |
| 443 |
\end{desc} |
| 444 |
|
| 445 |
Add a command or a variable to the list of ``marks'' to be emitted at |
| 446 |
a sectioning command. The macro must be parameterless, and the |
| 447 |
variable is either a length, if it has the form \verb|\<name>|, or a |
| 448 |
counter, if it has the form \verb|<name>| (i. e., a string). |
| 449 |
For example, if you write (with \textsf{babel}): |
| 450 |
\begin{verbatim} |
| 451 |
\newtitlemark{\languagename} |
| 452 |
\end{verbatim} |
| 453 |
then a |\languagename| in the head/foot will contain the language when |
| 454 |
the corresponding mark was emitted; unfortunately, \textsf{babel} |
| 455 |
does not allow |\languagename| as the first argument of |
| 456 |
|\foreignlanguage| (it enters in a infinite loop), but there is a |
| 457 |
simple trick -- just use an intermediate command: |
| 458 |
\begin{verbatim} |
| 459 |
\newcommand\titlelanguage{\languagename} |
| 460 |
\newtitlemark{\titlelanguage} |
| 461 |
\end{verbatim} |
| 462 |
(What is saved is the expansion of |\titlelanguage|, which is turn is |
| 463 |
the expansion of |\languagename|. Alternatively, you can create the |
| 464 |
intermediate command with |\let| in the header itself.) |
| 465 |
|
| 466 |
Marks to be emitted at other places (not sectioning commands) are |
| 467 |
handled with extra marks and \textit{marksets} (see below). |
| 468 |
|
| 469 |
Commands must be robust, but not protected, or the value returned will |
| 470 |
not be the right one. Remember there are two kinds of robust commands |
| 471 |
-- those containing in turn robust commands and those protected with, |
| 472 |
say, |\DeclareRobustCommand|.\footnote{Unfortunately, |
| 473 |
\texttt{\string\DeclareRobustCommand} has a misleading name, because a |
| 474 |
command created with \texttt{\string\newcommand} can be robust, too. |
| 475 |
A better name would have been |
| 476 |
\texttt{\string\DeclareProtectedCommand}.} An example of how to use |
| 477 |
protected commands is a layout used sometimes if sections are long as |
| 478 |
well as their titles, where the title is splitted across the left and |
| 479 |
the right pages. Here is how this can be carried out: |
| 480 |
\begin{verbatim} |
| 481 |
\DeclareRobustCommand\splitheader[2]{#1 #2} |
| 482 |
\def\contsplitheader{} |
| 483 |
|
| 484 |
\def\dosplitheader{% |
| 485 |
\gdef\contsplitheader{}% |
| 486 |
\DeclareRobustCommand\splitheader[2]{##1\gdef\contsplitheader{##2}}} |
| 487 |
|
| 488 |
\renewpagestyle{headings}{ |
| 489 |
\sethead[\thepage] |
| 490 |
[] |
| 491 |
[\dosplitheader\sectiontitle] |
| 492 |
{\contsplitheader} |
| 493 |
{} |
| 494 |
{\thepage} |
| 495 |
} |
| 496 |
|
| 497 |
\pagestyle{headings} |
| 498 |
\end{verbatim} |
| 499 |
(Note the header also uses |\DeclareRobustCommand|.) |
| 500 |
|
| 501 |
\begin{desc} |
| 502 |
|\pretitlemark{<section>}{<text>}|\\ |
| 503 |
|\pretitlemark*{<section>}{<text>}| |
| 504 |
\end{desc} |
| 505 |
|
| 506 |
Top marks require in fact two marks, one before the page break and |
| 507 |
other after it. This is done by \textsf{titlesec}, while |
| 508 |
\textsf{titleps} patches the sectioning commands as described above. |
| 509 |
|
| 510 |
However, if you need an explicit page break you can emit the mark |
| 511 |
with |\pretitlemark|. For example: |
| 512 |
\begin{verbatim} |
| 513 |
\pretitlemark{section}{Performing Brahms} |
| 514 |
\newpage |
| 515 |
\section{Performing Brahms} |
| 516 |
\end{verbatim} |
| 517 |
Note the text in the premark is the title of the next section. The |
| 518 |
counter is advanced temporarily, so that it has the right value, but |
| 519 |
if for some reason you do not want that, just use |
| 520 |
\verb|\pretitlemark*|. |
| 521 |
|
| 522 |
\begin{desc} |
| 523 |
|\ifsamemark{<group>}{<command>}{<true>}{<false>}| |
| 524 |
\end{desc} |
| 525 |
|
| 526 |
One of the disavantaged of the switching mechanism is that comparing |
| 527 |
a command from, say, the top marks and the botttom marks is not |
| 528 |
trivial. |
| 529 |
This macro just makes it simpler. If you want to compare the |
| 530 |
currect \verb|\thesection| with that in the top mark, write: |
| 531 |
\begin{verbatim} |
| 532 |
\ifsamemark\toptitlemarks\thesection{<true>}{<false>} |
| 533 |
\end{verbatim} |
| 534 |
|
| 535 |
\section{Running heads with floats} |
| 536 |
|
| 537 |
\begin{desc} |
| 538 |
|psfloats| \qquad (package option) |
| 539 |
\end{desc} |
| 540 |
|
| 541 |
This package option activates the commands described in this section.% |
| 542 |
\footnote{It redefines some internal \LaTeX{} commands and there could be |
| 543 |
incompatibilities with other packages modifying the same commands. That's |
| 544 |
the very reason these commands are loaded only optionally. As of |
| 545 |
version 2.6 the syntax was extended with a new argument to allow |
| 546 |
extra stuff in running heads/foots. This change is backward |
| 547 |
compatible---just preserve the old name \verb|floatps|, which |
| 548 |
is deprecated, if you want the pre-2.6 behaviour.} |
| 549 |
|
| 550 |
\begin{desc} |
| 551 |
|\setfloathead*{.}{.}{.}{<extra>}[<which-floats>]|\\ |
| 552 |
|\setfloathead[.][.][.]{.}{.}{.}{<extra>}[<which-floats>]|\\ |
| 553 |
(Similarly |\setfloatfoot|.) |
| 554 |
\end{desc} |
| 555 |
|
| 556 |
The arguments with a dot are similar to those of |\sethead|. The final |
| 557 |
argument says the head is used when there is a float of |
| 558 |
the specified types (default is |tp| in headers, and |bp| in footers). |
| 559 |
For example: |
| 560 |
\begin{verbatim} |
| 561 |
\newpagestyle{main}{% |
| 562 |
\sethead ... your definition |
| 563 |
\setfoot ... your definition |
| 564 |
\headrule |
| 565 |
\footrule |
| 566 |
\setfloathead{}{}{}{\setheadrule{0pt}}[p] |
| 567 |
\setfloatfoot{}{}{}{\setfootrule{0pt}}[p]} |
| 568 |
\end{verbatim} |
| 569 |
removes the header/footer on float pages, including the rules. |
| 570 |
|
| 571 |
\begin{desc} |
| 572 |
|\nextfloathead*{.}{.}{.}{<extra>}[<which-floats>]|\\ |
| 573 |
|\nextfloathead[.][.][.]{.}{.}{.}{<extra>}[<which-floats>]|\\ |
| 574 |
(Similarly |\nextfloatfoot|.) |
| 575 |
\end{desc} |
| 576 |
|
| 577 |
You may force a header (respectively footer) when a certain float is |
| 578 |
the first top one (respectively last bottom) with those commands just |
| 579 |
before the corresponding float, where the arguments with a dot are |
| 580 |
similar to those of |\sethead|. Those commands are used by |
| 581 |
themselves, without putting them inside |\(re)newpagestyle|. So, to |
| 582 |
empty the headline when a certain figure is placed at the top (because |
| 583 |
it is a bleed, for example): |
| 584 |
\begin{verbatim} |
| 585 |
\nextfloathead{}{}{}{}[t] |
| 586 |
\begin{figure} |
| 587 |
... |
| 588 |
\end{figure} |
| 589 |
\end{verbatim} |
| 590 |
|
| 591 |
\section{Extra marks} |
| 592 |
|
| 593 |
Both \textsf{titlesec} and \textsf{titleps} provide tools for handling |
| 594 |
extra marks, if you are using an $\epsilon$-\TeX{} based engine |
| 595 |
(currently most of them) and load the \textsf{etex} package or |
| 596 |
equivalent. The way they work are conceptually similar to the title |
| 597 |
marks described above -- you set which commands or variables are to |
| 598 |
get synchronized in heads and foots. To use extra marks, you have to |
| 599 |
load them with the following package option: |
| 600 |
|
| 601 |
\begin{desc} |
| 602 |
|extramarks| \qquad (package option) |
| 603 |
\end{desc} |
| 604 |
|
| 605 |
Extra marks are subsidiary. If page styles are modified internally by |
| 606 |
another package and the document does not make use of sectioning |
| 607 |
commands, you might still need an empty title mark (like |
| 608 |
\verb|\sectionmark{}|), as well as to synchronize the language by |
| 609 |
hand. |
| 610 |
|
| 611 |
In many cases, the following ``short'' marks mechanism will be enough. |
| 612 |
With it, you simply say with \verb|\newshormark| the name of a command |
| 613 |
to be used in heads or foots, and then emit the mark at appropiated |
| 614 |
places (short marks for variables are not available). An example |
| 615 |
illustrates how this is carried out: |
| 616 |
\begin{verbatim} |
| 617 |
\newcommand\lemmatitle{} |
| 618 |
|
| 619 |
\newshortmark\lemmatitle |
| 620 |
|
| 621 |
\newcommand\lemma[1]{% |
| 622 |
\renewcommand\lemmatitle{#1}% |
| 623 |
\preshortmark\lemmatitle % if you want top marks |
| 624 |
\pagebreak[2]% |
| 625 |
\vspace{1em}% |
| 626 |
\textbf{#1}\enspace |
| 627 |
\shortmark\lemmatitle} |
| 628 |
|
| 629 |
\newpagestyle{main}{ |
| 630 |
\sethead{}{\topshortmark\lemmatitle |
| 631 |
--\firstshortmark\lemmatitle |
| 632 |
--\botshortmark\lemmatitle |
| 633 |
--\nexttopshortmark\lemmatitle}{}} |
| 634 |
|
| 635 |
\pagestyle{main} |
| 636 |
\end{verbatim} |
| 637 |
|
| 638 |
Top marks require emitting the marks before the page break -- just use |
| 639 |
the command \verb|\preshortmark| as shown above. Otherwise, you may |
| 640 |
omit it. Unlike title marks and extra marks, the selector of short |
| 641 |
marks (\verb|\topshortmark|, \verb|\firstshortmark|, |
| 642 |
\verb|\botshortmark|, \verb|\nexttopshortmark|), is \textit{not} a |
| 643 |
switch and must be always immediately followed by the command to be |
| 644 |
retrieved. |
| 645 |
|
| 646 |
For a more general approach use the following tools. |
| 647 |
|
| 648 |
\begin{desc} |
| 649 |
|\newmarkset{<markset>}| |
| 650 |
\end{desc} |
| 651 |
|
| 652 |
A \textit{markset} contains a set of related commands and variables |
| 653 |
intended to be emitted simultaneously as marks, so that their values |
| 654 |
can be retrieved in heads/foots. A typical \textit{markset} could be |
| 655 |
a title and its counter (and perhaps, in a multilingual document, the |
| 656 |
active language, i.e., \verb|\languagename| in \textsf{babel}, or an |
| 657 |
intermediate command). There is always a special unnamed |
| 658 |
\textit{markset} for sectioning marks, which is the main one and |
| 659 |
handled with the tools described above (with |title| in their names). |
| 660 |
|
| 661 |
\begin{desc} |
| 662 |
|\newextramark{<markset>}{<macro-name>}|\\ |
| 663 |
|\newextramark*{<markset>}{<variable-name>}| |
| 664 |
\end{desc} |
| 665 |
|
| 666 |
Add to a \textit{markset} a command or a variable to be synchronized . |
| 667 |
They are identical to \verb|\newtitlemark| and \verb|\newtitlemark*|, |
| 668 |
except for the additional parameter with the \textit{markset} name. |
| 669 |
|
| 670 |
\begin{desc} |
| 671 |
|\botextramarks{<markset>} \topextramarks{<markset>}|\\ |
| 672 |
|\firstextramarks{<markset>} \nexttopextramarks{<markset>}|\\ |
| 673 |
|\outerextramarks{<markset>} \innerextramarks{<markset>}| |
| 674 |
\end{desc} |
| 675 |
|
| 676 |
The \verb|extra| counterparts of the \verb|title| commands described |
| 677 |
above, with the same behaviour. For example: |
| 678 |
\begin{verbatim} |
| 679 |
\newcommand{\lemmatitle}{} |
| 680 |
\newcounter{lemma} |
| 681 |
|
| 682 |
\newmarkset{lemma} |
| 683 |
\newextramark{lemma}{\lemmatitle} |
| 684 |
\newextramark*{lemma}{lemma} % ie, the counter `lemma' |
| 685 |
|
| 686 |
\newcommand{\lemma}[1]{% |
| 687 |
\renewcommand{\lemmatitle}{#1}% |
| 688 |
\stepcounter{lemma}% |
| 689 |
\preextramark{lemma}% |
| 690 |
\pagebreak[2]% |
| 691 |
\vspace{1em}% |
| 692 |
\textbf{(\arabic{lemma}) #1}\enspace |
| 693 |
\extramark{lemma}} |
| 694 |
|
| 695 |
\newpagestyle{main}{ |
| 696 |
\sethead{} |
| 697 |
{\topextramarks{lemma}(\arabic{lemma}) \textbf{\lemmatitle}} |
| 698 |
{}} |
| 699 |
|
| 700 |
\pagestyle{main} |
| 701 |
\end{verbatim} |
| 702 |
|
| 703 |
\begin{desc} |
| 704 |
|\settitlemarks*{<level-name>,<sublevel-name>,<subsublevel-name>...}| |
| 705 |
\end{desc} |
| 706 |
|
| 707 |
By default, \LaTeX{} and \textsf{titleps} use a single \textit{markset} for |
| 708 |
all sectioning levels. This is problematic, for example, in the |
| 709 |
\textsf{article} class, because sections does not start a new page. |
| 710 |
Consider the following piece of code: |
| 711 |
\begin{verbatim} |
| 712 |
\section{A section} |
| 713 |
\subsection{A subsection} |
| 714 |
\end{verbatim} |
| 715 |
On odd pages with first marks and subsection titles, the head has |
| 716 |
no title, because \verb|\subsection| is the second mark, not the |
| 717 |
first one. |
| 718 |
|
| 719 |
To overcome this limitation, you can use the starred version of |
| 720 |
\verb|\settitlemarks|, which creates parallel \textit{marksets} (one per |
| 721 |
level) synchonized with the main \textit{markset}. They are retrieved like |
| 722 |
other extra marks, but they are special in that you cannot emit them |
| 723 |
by yourself -- they are always emitted by the corresponding |
| 724 |
sectioning mark. So, with |
| 725 |
\begin{verbatim} |
| 726 |
\settitlemarks*{section,subsection} |
| 727 |
\end{verbatim} |
| 728 |
and a page style containing |
| 729 |
\begin{verbatim} |
| 730 |
\firstextramarks{subsection}\subsectiontitle |
| 731 |
\end{verbatim} |
| 732 |
you retrieve the mark emitted by the first \verb|\subsection|, even |
| 733 |
if preceded by a \verb|\section|. (Top marks are best retrieved from |
| 734 |
the main \textit{markset}.) |
| 735 |
|
| 736 |
They are extra marks, and therefore language synchronization has to be |
| 737 |
done by hand -- add \verb|\languagename| or an intermediate command to |
| 738 |
the main \textit{markset} with \verb|\newtitlemark| and, if you want, |
| 739 |
define a command. For example: |
| 740 |
\begin{verbatim} |
| 741 |
% use an intermediate command because we'll need \foreignlanguage |
| 742 |
\newcommand\titlelanguage{\languagename} |
| 743 |
\newtitlemark{\titlelanguage} |
| 744 |
|
| 745 |
% define a command to ease defining page styles |
| 746 |
\newcommand{\toplang}[1]{% |
| 747 |
{\topextramarks{section}% |
| 748 |
\foreignlanguage{\titlelanguage}{#1}}} |
| 749 |
\end{verbatim} |
| 750 |
|
| 751 |
\section{A couple of examples} |
| 752 |
|
| 753 |
Because of the way marks are handled, special constructs like this are |
| 754 |
allowed: |
| 755 |
\begin{verbatim} |
| 756 |
\newpagestyle{main}[\small\sffamily]{ |
| 757 |
\sethead[\textbf{\thepage}] |
| 758 |
[\textsl{\chaptertitle}] |
| 759 |
[[\toptitlemarks\thesection--\bottitlemarks\thesection] |
| 760 |
{\toptitlemarks\thesection--\bottitlemarks\thesection]} |
| 761 |
{\textsl{\sectiontitle}} |
| 762 |
{\textbf{\thepage}}} |
| 763 |
\end{verbatim} |
| 764 |
As you can see, the range of sections in a page with |\thesection| is |
| 765 |
printed in both left and right heads. Of course, this example should |
| 766 |
be fine tuned to collapse the ranges if there is a single section in a |
| 767 |
page (with |\ifsamemark|), but it gives a hint of how to get stunning |
| 768 |
headers. |
| 769 |
|
| 770 |
In this document, the following styles are used: |
| 771 |
\begin{verbatim} |
| 772 |
\widenhead{2.1pc}{0pc} |
| 773 |
\renewpagestyle{plain}[\small\sffamily\slshape]{ |
| 774 |
\footrule |
| 775 |
\setfoot{}{\thepage}{}} |
| 776 |
\newpagestyle{myps}[\small\sffamily\slshape]{ |
| 777 |
\headrule |
| 778 |
\sethead{titlesec -- titleps}{\sectiontitle}{\thepage}} |
| 779 |
\end{verbatim} |
| 780 |
|
| 781 |
The following definitions provide page styles similar to those in |
| 782 |
Lamport's \textit{The \LaTeX\ book} (with the \textsf{calc} package): |
| 783 |
\begin{verbatim} |
| 784 |
\widenhead*{0pt}{\marginparsep + \marginparwidth} % symmetrically |
| 785 |
\renewpagestyle{plain}{} |
| 786 |
\newpagestyle{latex}[\bfseries]{ |
| 787 |
\headrule |
| 788 |
\sethead[\thepage][][\chaptertitle] |
| 789 |
{\thesection\ \sectiontitle}{}{\thepage}} |
| 790 |
\pagestyle{latex} |
| 791 |
\end{verbatim} |
| 792 |
|
| 793 |
% \section{Remarks} |
| 794 |
% |
| 795 |
% Page styles in standard \LaTeX{} are somewhat rudimentary. For |
| 796 |
% example |\thispagestyle| is not always correctly synchronized with |
| 797 |
% sectioning marks, and if you set |\pagestyle{plain}| and then |
| 798 |
% |\thispagestyle{headings}|, its behaviour is not the expected one. |
| 799 |
% The same happens if a page style defined in \textsf{titleps} is used |
| 800 |
% in a |\thispagestyle| in the context of a standard page style -- you |
| 801 |
% have to define the main one as well. |
| 802 |
|
| 803 |
% \section{Some tips and tricks} |
| 804 |
% |
| 805 |
% star |\*| |
| 806 |
% |
| 807 |
% split heads |
| 808 |
% |
| 809 |
% bible |
| 810 |
|
| 811 |
\end{document} |
| 812 |
|
| 813 |
MIT License |
| 814 |
----------- |
| 815 |
|
| 816 |
Permission is hereby granted, free of charge, to any person obtaining a |
| 817 |
copy of this software and associated documentation files (the |
| 818 |
"Software"), to deal in the Software without restriction, including |
| 819 |
without limitation the rights to use, copy, modify, merge, publish, |
| 820 |
distribute, sublicense, and/or sell copies of the Software, and to |
| 821 |
permit persons to whom the Software is furnished to do so, subject to |
| 822 |
the following conditions: |
| 823 |
|
| 824 |
The above copyright notice and this permission notice shall be included |
| 825 |
in all copies or substantial portions of the Software. |
| 826 |
|
| 827 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 828 |
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 829 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 830 |
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 831 |
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 832 |
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 833 |
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 834 |
|
| 835 |
|