Debian Codegraph @

texmf-dist/doc/latex/titlesec/titlesec.tex

raw
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,color}
16 \def\gobble#1{}
17 \def\cs#1{\expandafter\gobble\string\\#1}
18 \definecolor{notes}{rgb}{.75, .3, .3}%
19 \makeatletter
20 \newenvironment{desc}
21 {\if@nobreak
22 \vskip-\lastskip
23 \vspace*{-2.5ex}%
24 \fi
25 \decl}
26 {\enddecl}
27 \def\@begintheorem#1#2{%
28 \list{}{}%
29 \global\advance\@listdepth\m@ne
30 \item[{\sffamily\bfseries\color{notes}\MakeUppercase{#1}}]}%
31 \newtheorem{warning}{Warning}
32 \newtheorem{note}{Note}
33 \newtheorem{example}{Example}
34 \makeatother
35
36 \usepackage{textcomp}
37 \usepackage[linktocpage]{hyperref}
38
39 \title{The \textsf{titlesec}, \textsf{titleps} and \textsf{titletoc}
40 Packages\footnote{The \textsf{titlesec} package is currently at
41 version 2.17. \copyright{} 1998--2025 Javier Bezos.}}
42
43 \author{Javier Bezos\footnote{For bug reports, comments and
44 suggestions go to \href{http://www.tex-tipografia.com/contact.html}%
45 {\texttt{http://www.tex-tipografia.com/contact.html}}. English
46 is not my strong point, so contact me when you find mistakes in the
47 manual. Other packages by the same author: \textsf{gloss} (with
48 Jos\'e Luis D\'{\i}az), \textsf{enumitem, accents, tensind, esindex,
49 dotlessi, babeltools}.}}
50
51 \date{\docdate}
52
53 \widenhead{2.1pc}{0pc}
54 \titlelabel{\thetitle.\quad}
55
56 \renewpagestyle{plain}[\small\sffamily\slshape]{
57 \footrule
58 \setfoot{}{\usepage}{}}
59
60 \newpagestyle{myps}[\small\sffamily\slshape]{
61 \headrule
62 \sethead{Titlesec}{\sectiontitle}{\usepage}}
63
64 \pagestyle{myps}
65
66 \newcommand{\examplesep}{%
67 \begin{center}%
68 \rule{4pt}{4pt}%
69 \end{center}}
70
71 \contentsmargin{0pt}
72 \titlecontents{section}[1.8pc]
73 {\addvspace{3pt}\bfseries}
74 {\contentslabel[\thecontentslabel.]{1.8pc}}
75 {}
76 {\quad\thecontentspage}
77
78 \titlecontents*{subsection}[1.8pc]
79 {\small}
80 {\thecontentslabel. }
81 {}
82 {, \thecontentspage}
83 [.---][.]
84
85 \addtolength{\topmargin}{-3pc}
86 \addtolength{\textwidth}{6pc}
87 \addtolength{\oddsidemargin}{-2pc}
88 \addtolength{\textheight}{7pc}
89
90 \raggedright
91 \parindent1em
92 \parskip0pt
93
94 \begin{document}
95
96 \maketitle
97 \tableofcontents
98
99 \begin{note}
100 Please, report any issues you find on
101 \texttt{https://github.com/jbezos/titlesec/issues}, which is better
102 than just complaining on an e-mail list or a web forum. Forking
103 and pull requests are welcome.
104 \end{note}
105
106 \section{Introduction}
107
108 This package is essentially a replacement---partial or total---for the
109 \LaTeX{} macros related with sections---namely titles, headers and
110 contents. The goal is to provide new features unavailable in current
111 \LaTeX{}; if you just want a more friendly interface than that of
112 standard \LaTeX{} but without changing the way \LaTeX{} works you may
113 consider using \textsf{fancyhdr}, by Piet van Oostrum, \textsf{sectsty},
114 by Rowland McDonnell, and \textsf{tocloft}, by Peter Wilson, which you
115 can make pretty things with.\footnote{Since the sectioning commands
116 are rewritten, their behaviour could be somewhat different
117 in some cases.}
118
119 Some of the new features provided are:
120 \begin{itemize}
121 \item Different classes and ``shapes'' of titles, with tools for very
122 fancy formats. You can define different formats for left and right
123 pages, or numbered and unnumbered titles, measure the width of the
124 title, add a new section level, use graphics, and many more. The
125 Appendix shows a good deal of examples, so jump forward right now!
126
127 \item Headers and footers defined with no |\...mark| intermediates,
128 and perhaps containing top, first \emph{and} bot marks at the same time.
129 Top marks correctly synchronized with titles, without
130 incompatibilities with the float mechanism. Decorative elements easily
131 added, including picture environments.
132
133 \item Pretty free form contents, with the possibility of grouping
134 entries of different levels in a paragraph or changing the format
135 of entries in the middle of a document.
136 \end{itemize}
137 At the time of this writing, \textsf{titlesec} works with the standard
138 classes and should work with many others, including the AMS ones,
139 although you should be aware the latter reimplement the original
140 internal commands. These changes will be lost here.
141
142 \begin{warning}
143 Compatibility with \textsf{hyperref} has been tested in typical use
144 cases, but it is an unsupported feature. For instance, when
145 using |\titleclass|, PDF bookmarks may not be properly nested, and
146 |\nameref| might not function as expected. Furthermore, since
147 \textsc{hyperref} is actively developed, currently working features
148 may become non-functional over time. I regret these ‘known
149 issues’ are unlikely to be addressed in the near future.
150
151 It is not compatible with \textsf{memoir} or \textsf{KOMA}, which
152 provide their own tools.
153 \end{warning}
154
155 As usual, load the package in the standard way with
156 |\usepackage|. Then, redefine the sectioning commands with the
157 simple, predefined settings (see section ``Quick Reference'') or with
158 the provided commands if you want more elaborate formats (see section
159 ``Advanced Interface.'') In the latter case, you only need to
160 redefine the commands you'll use. Both methods are available at the
161 same time, but because |\part| is usually implemented in a
162 non-standard way, it remains untouched by the simple settings and
163 should be changed with the help of the ``Advanced Interface.''
164
165 \section{Quick Reference}
166 %~~~~~~~~~~~~~~~~~~~~~~
167
168 The easiest way to change the format is by means of a set of package
169 options and a couple of commands. If you feel happy with the
170 functionality provided by this set of tools, you need not go
171 further in this manual. Just read this section and ignore the
172 subsequent ones.
173
174 \subsection{Format}
175
176 There are three option groups controlling font, size and align. You
177 need not set all of these groups, since a default is provided for each
178 one; however, you must use at least an option from them if you want
179 this ``easy setup''.
180 \begin{desc}
181 |rm sf tt md bf up it sl sc|
182 \end{desc}
183 Select the corresponding family/series/shape. Default is |bf|.
184
185 \begin{desc}
186 |big medium small tiny|
187 \end{desc}
188 Set the size of titles.
189 Default is |big|, which gives the size of standard classes.
190 With |tiny|, sections (except chapters) are typed in the text
191 size. |medium| and |small| are intermediate layouts.
192
193 \begin{desc}
194 |raggedleft center raggedright|
195 \end{desc}
196
197 Control the alignment.
198
199 \subsection{Spacing}
200
201 \begin{desc}
202 |compact|
203 \end{desc}
204 This option is independent from those above and reduces the spacing
205 above and below the titles.
206
207 \subsection{Uppercase}
208
209 \begin{desc}
210 |uppercase|
211 \end{desc}
212
213 \fbox{2.9} Uppercases titles. Depending on the class, it might not work in
214 \verb|\chapter| and \verb|\part|.
215
216 \subsection{Tools}
217
218 \begin{desc}
219 |\titlelabel{<label-format>}|
220 \end{desc}
221 Changes the label format in sections, subsections, etc. A
222 |\thetitle| command is provided which is respectively |\thesection|,
223 |\thesubsection|, etc. The default value in standard classes is
224 \begin{verbatim}
225 \titlelabel{\thetitle\quad}
226 \end{verbatim}
227 and you may add a dot after the counter simply with
228 \begin{verbatim}
229 \titlelabel{\thetitle.\quad}
230 \end{verbatim}
231 That was done in this document.
232
233 \begin{desc}
234 |\titleformat*{<command>}{<format>}|
235 \end{desc}
236
237 This command allows to change the |<format>| of a sectioning
238 command, as for example:
239 \begin{verbatim}
240 \titleformat*{\section}{\itshape}
241 \end{verbatim}
242
243 \section{Advanced Interface}
244 %~~~~~~~~~~~~~~~~~~~~~~~~
245
246 Two commands are provided to change the title format. The first one
247 is used for the ``internal'' format, i.e., shape, font, label\dots,
248 the second one defines the ``external'' format, i.e., spacing before
249 and after, indentation, etc. This scheme is intended to easy
250 definitions, since in most of cases you will want to modify either
251 spacing or format.\footnote{Information is ``extracted'' from the
252 class sectioning commands, except for chapter and part. Standard
253 definitions with |\cs{@startsection}| are presumed---if sections have
254 been defined without that macro, arbitrary values for the format an
255 the spacing are provided, which you may change later. (Sadly, there
256 is no way to catch the chapter or part formats, and one similar to
257 that of standard classes will be used.)} That redefines existing
258 sectioning commands, but does not create \emph{new} ones. New
259 sectioning levels can be added with |\titleclass|, as described below,
260 and then their format can be set with the commands described here.
261
262 \subsection{Format}
263
264 A set of shapes is provided, which controls the basic distribution of
265 elements in the title. The available shapes are:
266 \begin{description}
267 \item[hang] is the default value, with a hanging label. (Like the
268 standard |\section|.)
269
270 \item[block] typesets the whole title in a block (a paragraph) without
271 additional formatting. Useful in centered titles\,\footnote{The label
272 will be slightly displaced to the left if the title is two or more
273 lines long and the \texttt{hang} shape is used, except with explicit
274 |\string\\|.} and special formatting (including graphic tools such as
275 |picture|, |pspicture|, etc.)
276
277 \item[display] puts the label in a separate paragraph. (Like the
278 standard |\chapter|.)
279
280 \item[runin] A run-in title, like the standard
281 |\paragraph|.\footnote{Well, not quite. The title is first boxed to
282 avoid some unexpected results if, for example, there is a
283 \texttt{\string\color} between the title and the
284 text. Unfortunately, due to an optimization done by \TeX{}
285 discretionaries may be lost. I have found no solution, except using
286 \textsf{luatex}, which works as one could expect. Anyway, if the
287 title doesn't contain hyphen or dashes, this is not usually a real
288 problem.}
289
290 \item[leftmargin] puts the title at the left margin. Titles at the
291 very end of a page will be moved to the next one and will not stick
292 out in the bottom margin, which means large titles can lead to
293 underfull pages.\footnote{However, floats following the title a couple
294 of lines after will interfere with the page breaking used here and
295 sometimes the title may stick out.} In this case you may increase the
296 stretchability of the page elements, use |\raggedbottom| or use the
297 package option |nobottomtitles| described below. Since the mechanism
298 used is independent from that of the margin pars, they can overlap.
299 A deprecated synonymous is |margin|.
300
301 \item[rightmargin] is like |leftmargin| but at the right margin.
302
303 \item[drop] wraps the text around the title, provided the
304 first paragraph is longer than the title (if not, they overlap).
305 The comments in |leftmargin| also apply here.
306
307 \item[wrap] is quite similar to drop. The only difference is
308 while the space reserved in drop for the title is fixed, in wrap is
309 automatically readjusted to the longest line. The limitations
310 explained below related to |calcwidth| also apply here.
311
312 \item[frame] Similar to display, but the title will be framed.
313 \end{description}
314
315 Note, however, some shapes do not make sense in chapters and
316 parts.
317
318 \begin{desc}
319 |\titleformat{<command>}[<shape>]{<format>}{<label>}{<sep>}{<before-code>}[<after-code>]|
320 \end{desc}
321
322 Here
323 \begin{itemize}
324 \item |<command>| is the sectioning command to be redefined, i.e.,
325 |\part|,
326 |\chapter|, |\section|, |\subsection|, |\subsubsection|, |\paragraph|
327 or |\subparagraph|.
328
329 \item The paragraph shape is set by |<shape>|, whose possible
330 values are those described above.
331
332 \item |<format>| is the format applied to the whole
333 title---label and text. This part can contain vertical material (and
334 horizontal with some shapes) which is typeset just after the space
335 above the title.
336
337 \item The label is defined in |<label>|. You may leave it empty if
338 there is no section label at that level, but this is not recommended
339 because by doing so the number is not suppressed in the table of
340 contents and running heads.
341
342 \item |<sep>| is the horizontal separation between label and title
343 body and must be a length (it must not be empty). This space is
344 vertical in |display| shape; in |frame| it is the distance from text
345 to frame. Both |<label>| and |<sep>| are ignored in starred versions
346 of sectioning commands. If you are using |picture| and the like, set
347 this parameter to 0 pt.
348
349 \item |<before-code>| is the code preceding the title body. The very last
350 command can take an argument, which is the title
351 text.\footnote{Remember font size can be changed safely between
352 paragraphs only, and changes in the text should be made local with a
353 group; otherwise the leading might be wrong---too large or too small.}
354 However, with the package option \texttt{explicit} the title must be
355 given explicitly with |#1| (see below). Penalties in this argument may
356 lead to unexpected results.
357
358 \item |<after-code>| is the code following the title body. The typeset
359 material is in vertical mode with |hang|, |block| and |display|; in
360 horizontal mode with |runin| and |leftmargin| (\fbox{2.7} with the
361 latter, at the beginning of the paragraph). Otherwise is ignored.
362 Penalties in this argument may lead to unexpected results.
363 \end{itemize}
364
365 Penalties, marks and the like must be properly synchronized with page
366 breaks. So, |<before-code>| and |<after-code>| are \textit{not} the
367 proper places for penalties. See |\sectionbreak| below.
368
369 \begin{warning}
370 Because of the way colors are internally ‘stacked’ you can find some
371 anomalous results if |\color| is used in some shapes, namely |wrap|,
372 |drop|, |leftmargin| and |rightmargin|. Either wrap the text with
373 |\textcolor| or place the code inside a group.
374 \end{warning}
375
376 \begin{desc}
377 |\chaptertitlename|
378 \end{desc}
379
380 It defaults to |\chaptername| except in appendices where it
381 is |\appendixname|. Use it instead of |\chaptername| when defining
382 a chapter.
383
384 \subsection{Spacing}
385
386 \begin{desc}
387 |\titlespacing*{<command>}{<left>}{<before-sep>}{<after-sep>}[<right-sep>]|
388 \end{desc}
389
390 The starred version kills the indentation of the paragraph
391 following the title, except in |drop|, |wrap| and |runin| where this
392 possibility does not make sense.
393 \begin{itemize}
394 \item |<left>| increases the left margin, except in the |...margin|,
395 and |drop| shapes, where this parameter sets the title width, in
396 |wrap|, the maximum width, and in |runin|, the indentation just before
397 the title. With negative value the title overhangs.\footnote{This
398 parameter is not equal to |<indent>| of |\cs{@startsection}|, which
399 doesn't work correctly. With a negative value in the latter and if
400 |<indent>| is larger than the label width, the first line of the title
401 will start in the outer margin, as expected, but the subsequent lines
402 will not; worse, those lines will be shortened at the right margin.}
403
404 \item |<before-sep>| is the vertical space before the title. The
405 standard |\chapter| inserts it with a |\vspace*|, and so does
406 \textsf{titlesec}; this means you have to take into account other
407 possible spaces inserted by \LaTeX\ at the op of the page.
408
409 \item |<after-sep>| is the separation between title and text---vertical
410 with |hang|, |block|, and |display|, and horizontal with |runin|,
411 |drop|, |wrap| and |...margin|. By making the value negative, you may
412 define an effective space of less than |\parskip|.\footnote{See
413 Goossens, Mittelbach and Samarin: \textit{The \LaTeX{} Companion},
414 Reading, Addison Wesley, 1993, p.~25.}
415
416 \item The |hang|, |block| and |display| shapes have the
417 possibility of increasing the |<right-sep>| margin with this optional
418 argument.
419 \end{itemize}
420
421 If you dislike typing the full skip values, including the |plus| and
422 |minus| parameters, an abbreviation |*|$n$ is provided. In the
423 |<before-sep>| argument this is equivalent to $n$ |ex| with some
424 stretchability and a minute shrinkability. In the
425 |<after-sep>| some stretchability (smaller) and no shrinkability.%
426 \footnote{They stand for $n$ times |1ex plus .3ex minus .06ex| and
427 |1ex plus .1ex|, respectively.} Thus, you can write
428 \begin{verbatim}
429 \titlespacing{\section}{0pt}{*4}{*1.5}
430 \end{verbatim}
431 The lengths |\beforetitleunit| and |\aftertitleunit| are used
432 as units in the |*| settings and you can change them if you do not like
433 the predefined values (or for slight changes in the makeup, for
434 example).
435
436 \begin{note}
437 |\titlespacing| does not work with either |\chapter| and |\part|
438 unless you change its title format as well by means of
439 |\titleformat|, the simple settings, or |\titleclass|.
440 \end{note}
441
442 \begin{note}
443 Arguments in |\titlespacing| must be dimensions; |\stretch| includes
444 a command and hence raises an error.
445 \end{note}
446
447 \subsection{Spacing related tools}
448
449 These commands are provided as tools for |\titleformat| and
450 |\titlespacing|.
451
452 \begin{desc}
453 |\filright \filcenter \filleft \fillast \filinner \filouter|
454 \end{desc}
455
456 Variants of the |\ragged...| commands, with slight differences. In
457 particular, the |\ragged...| commands kills the left and right spaces
458 set by |\titlespacing|.\footnote{Remember the package
459 \textsf{ragged2e} provides some additional commands for alignment,
460 too, like \texttt{\string\justifying}.} |\fillast| justifies the
461 paragraph, except the last line which is
462 centered.\footnote{Admittedly, a weird name, but it is short.} These
463 commands work in the |frame| label, too.
464
465 |\filinner| and |\filouter| are |\filleft| or |\filright| depending
466 on the page. Because of the asynchronous \TeX{} page
467 breaking, these commands can be used in |\chapter| only.
468 If you want a general tool to set different formats depending
469 on the page, see ``Extended settings'' below.
470
471 \begin{desc}
472 |\wordsep|
473 \end{desc}
474
475 The inter-word space for the current font.
476
477 \begin{desc}
478 |indentafter noindentafter| \quad (Package options)
479 \end{desc}
480
481 By-pass the settings for all of sectioning commands.%
482 \footnote{Formerly |indentfirst| and |nonindentfirst|, now
483 deprecated.}
484
485 \begin{desc}
486 |rigidchapters rubberchapters| \quad (Package options)
487 \end{desc}
488
489 With |rigidchapters| the space for chapter titles is always the same,
490 and |<after-sep>| in |\titlespacing| does not mean the space from the
491 bottom of the text title to the text body as described above, but from
492 the \textit{top} of the text title, i.e., |<before-sep>| $+$
493 |<after-sep>| now is a fixed distance from the top of the page body to
494 the main text. The default is |rubberchapters| where |<after-sep>| is
495 the separation between title and text as usual. Actually, the name is
496 misleading because it applies not only to the default chapter, but to
497 any title of top class. (More on classes below.)
498
499 \begin{desc}
500 |bottomtitles nobottomtitles nobottomtitles*| \quad (Package options)
501 \end{desc}
502
503 If |nobottomtitles| is set, titles close to the bottom margin will
504 be moved to the next page and the margin will be ragged. The minimal
505 space required in the bottom margin not to move the title is set
506 (approximately) by
507 \begin{verbatim}
508 \renewcommand{\bottomtitlespace}{<length>}
509 \end{verbatim}
510 whose default value is |.2\textheight|. A simple ragged bottom on the
511 page before is obtained with a value of 0 pt. |bottomtitles| is the
512 default, which simply sets |\bottomtitlespace| to a negative value.
513
514 The |nobottomtitles*| option provides more accurate computations but
515 titles of |margin|, |wrap| or |drop| shapes could be badly
516 placed. Usually, you should use the starred version.
517
518 \begin{desc}
519 |aftersep largestsep| \quad (Package options)
520 \end{desc}
521
522 By default, when there are two consecutive titles the |<after-sep>|
523 space from the first one is used between them. Sometimes this is not
524 the desired behaviour, especially when the |<before-sep>| space is much
525 larger than the |<after-sep>| one (otherwise the default seems
526 preferable). With |largestsep| the largest of them is used. Default is
527 |aftersep|. [\textbf{Note.} |largestsep| may not work as documented.
528 This is a known issue.]
529
530 \begin{desc}
531 |\\ \\*|\\
532 |pageatnewline| \quad (Package option)
533 \end{desc}
534
535 \fbox{2.6} In version 2.6 and later, \verb|\\| does not allow a page
536 break and therefore is equivalent to \verb|\\*|. Since I presume none
537 wants a page break inside a title, this has been made the default. If
538 for some strange reason you want to allow page breaks inside the
539 titles, use the package option \verb|pageatnewline|, which is provided
540 for backward compatibility.
541
542 \begin{desc}
543 |\nostruts|\\
544 |nostruts| \quad (Package option)
545 \end{desc}
546
547 \fbox{2.11} The styles defined by \textsf{titlesec} insert some struts
548 at certain places to make sure the vertical space is the same with
549 relation with the baseline. This is not always the desired behavior, so
550 the package options |nostruts| is provided. An alternative is the macro
551 |\nostruts| when defining a section (note this macro is defined only
552 within a title).
553
554 \subsection{Rules}
555
556 The package includes some tools for helping in adding rules and other
557 stuff below or above the title. Since the margins in titles may be modified,
558 these macros take into account the local settings to place rules properly.
559 They also take into account the space used by marginal titles.
560
561 \begin{desc}
562 |\titleline[<align>]{<horizontal material>}|\\
563 |\titlerule[<height>]|\\
564 |\titlerule*[<width>]{<text>}|
565 \end{desc}
566
567 The |\titleline| command allows inserting a line, which may
568 contain text and other ``horizontal'' material. It is intended
569 mainly for rules and leaders but in fact is also useful for other
570 purposes. The line has a fixed width and hence must be filled, i.e.,
571 |\titleline{CHAPTER}| produces an underfull box. Here the optional
572 |<align>| (|l|, |r| or |c|) helps, so that you simply type, say,
573 |\titleline[c]{CHAPTER}|.%
574 \footnote{The default is the \texttt{s} parameter of the
575 \texttt{\cs{makebox}} command.}
576
577 Using |\titleline| in places where vertical material is not expected
578 can lead to anomalous results. In other words, you can use it in the
579 |<format>| (always) and |<after-code>| (|hang|, |display| and |block|)
580 arguments; and in the |display| shape at the very beginning of the
581 |<before-code>| and |<label>| argument as well. But try it out, because
582 very likely it works in other places.
583
584 The |\titlerule| command, which is enclosed automatically in
585 |\titleline| if necessary, can be used to build rules and
586 fillers. The unstarred
587 version draws rules of height .4 pt, or |<height>| if present.
588 For example:
589 \begin{verbatim}
590 \titlerule[.8pt]%
591 \vspace{1pt}%
592 \titlerule
593 \end{verbatim}
594 draws two rules of different heights with a separation of
595 1 pt.
596
597 The starred version makes leaders with the |<text>|
598 repeated in boxes of its natural width. The width of the boxes
599 can be changed to |<width>|, but the first box remains with
600 its natural width so that the |<text>| is aligned to the left
601 and right edges of the space to be filled.
602
603 For instance, with
604 \begin{verbatim}
605 \titleformat{\section}[leftmargin]
606 {\titlerule*[1pc]{.}%
607 \vspace{1ex}%
608 \bfseries}
609 {... definition follows
610 \end{verbatim}
611 leaders spanning over both main text and title precede the section.
612
613 \begin{desc}
614 |calcwidth| \quad (Package option)
615 \end{desc}
616
617 The |wrap| shape has the capability of measuring the lines in the title
618 to format the paragraph. This capability may be extended to other
619 three shapes---namely |display|, |block| and |hang|---with this
620 package option. The length of the longest line is returned in
621 |\titlewidth|.\footnote{There are two further
622 parameters, |\string\titlewidthfirst| and |\string\titlewidthlast|,
623 which return the length of the first and last lines. There are not
624 specific tools for using them, but you can assign their values to
625 |\string\titlewidth| and then use |\string\titleline*|.}
626
627 As far as \TeX{} is concerned, any box is considered typeset material.
628 If the box has been enlarged with blank space, or if conversely a box
629 with text has been smashed, the value of |\titlewidth| may be wrong
630 (as far as humans is concerned). The |hang| shape, for instance, uses
631 internally such a kind of boxes, but in this case this behaviour is
632 desired when the title is flushed right; otherwise the |block| shape
633 produces better results. In other words, using boxes whose natural
634 width has been overridden may be wrong.\footnote{Which include
635 justified lines, whose interword spacing has been enlarged.} Further,
636 some commands may confuse \TeX{} and stop parsing the title. But if
637 you stick to text, |\\| and |\\[...]| (and it is very unlikely you
638 might want something else), there will be no problems.
639
640 Another
641 important point is the |<before-code>|, |<label>|, |<sep>|, and
642 |<title>| parameters (but not |<after-code>|) are evaluated twice at local
643 scope; if you increase a counter \emph{globally}, you are increasing
644 it twice. In most of cases, placing the conflicting assignment in the
645 |<after-code>| parameter will be ok, but alternativey you can use the
646 following macro.
647
648 \begin{desc}
649 |\iftitlemeasuring{<true>}{<false>}|
650 \end{desc}
651
652 \fbox{2.9} When the title is being measured (first pass), the |<true>|
653 branch is used, and when the title is actually typeset (second pass)
654 the |<false>| branch is used.
655
656 \begin{desc}
657 |\titleline*[<align>]{<horizontal material>}|
658 \end{desc}
659 A variant of |\titleline| to be used only with |calcwidth|.
660 The text will be enclosed first in a box of width |\titlewidth|; this box
661 will be in turn enclosed in the main box with the specified alignment.
662 There is no equivalent |\titlerule| and therefore you must enclose
663 it explicitly in a |\titleline*| if you want the |\titlewidth| to
664 be taken into account:
665 \begin{verbatim}
666 \titleline*[c]{\titlerule[.8pc]}
667 \end{verbatim}
668
669 \subsection{Page styles}
670
671 \fbox{2.8} You can assign a page style to levels of class |top| and
672 |page|, as well as the default chapter with the following command:%
673 \footnote{Named in the short-lived version 2.7 as
674 \texttt{\string\titlepagestyle}.}
675 \begin{desc}
676 |\assignpagestyle{<command>}{<pagestyle>}|
677 \end{desc}
678 For example, to suppress the page number in chapters write:
679 \begin{verbatim}
680 \assignpagestyle{\chapter}{empty}
681 \end{verbatim}
682
683 \subsection{Breaks}
684
685 \begin{desc}
686 |\sectionbreak \subsectionbreak \subsubsectionbreak|\\
687 |\paragraphbreak \subparagraphbreak \<section>break|
688 \end{desc}
689
690 By defining these command with |\newcommand| different page breaks
691 could be applied to different levels. In those undefined, a penalty
692 with the internal value provided by the class is used (typically
693 $-300$). For instance,
694 \begin{verbatim}
695 \newcommand{\sectionbreak}{\clearpage}
696 \end{verbatim}
697 makes sections begin a new page. In some layouts, the space
698 above the title is preserved even if the section begins a new
699 page; that's accomplished with:
700 \begin{verbatim}
701 \newcommand{\sectionbreak}{%
702 \addpenalty{-300}%
703 \vspace*{0pt}}
704 \end{verbatim}
705
706 \fbox{2.6} \verb|\<section>break| is available in the \verb|top| class,
707 too. Suitable values would be \verb|\cleardoublepage| (the default if
708 \verb|openright|) and \verb|\clearpage| (the default if
709 \verb|openany|). Thus, you can override \verb|openright| by defining
710 \verb|\chapterbreak| as \verb|\clearpage|, provided its class has been
711 changed to \verb|top| (in this example, parts will continue with the
712 \verb|openright| setting).
713
714 Note these macros apply the penalties at the right place. In other
715 words, penalties in |<before-code>| and |<after-code>| can lead to
716 unexpected (and even weird) results.
717
718 \begin{desc}
719 |\chaptertolists|
720 \end{desc}
721
722 \fbox{2.6} If defined, the usual white space written to lists (ie,
723 List of Figures and List of Tables) is replaced by the code in this
724 command. If you do not want the white space when a chapter begins,
725 define it to empty, i.e.,
726 \begin{verbatim}
727 \newcommand{\chaptertolists}{}
728 \end{verbatim}
729
730 This command is not a general tool to control
731 spacing in lists, and is available only in titles of top class, so
732 it will not work with the default chapters except if you change their
733 class (on the other hand, |\...tolists| can be used in any title whose
734 class is top).
735
736 \subsection{Other Package Options}
737
738 \begin{desc}
739 |explicit| \quad (Package option)
740 \end{desc}
741
742 \fbox{2.7} With it, the title is not implicit after |<before-code>| but
743 must be given explicitly with |#1| as in, for example:
744 \begin{verbatim}
745 \titleformat{\section}
746 {..}
747 {\thesection}{..}{#1.}
748 \end{verbatim}
749 (Compare it with the example in section \ref{sec:dotafter}.)
750
751 \begin{desc}
752 |newparttoc oldparttoc| \quad (Package options)
753 \end{desc}
754
755 Standard parts write the toc entry number in a non standard way.
756 You may change that with |newparttoc| so that \textsf{titletoc}
757 or a similar package can manipulate the entry. (That works only if
758 |\part| has been redefined.)
759
760 \begin{desc}
761 |clearempty| \quad (Package options)
762 \end{desc}
763
764 Modifies the behaviour of |\cleardoublepage| so that the |empty| page
765 style will be used in empty pages.
766
767 \begin{desc}
768 |toctitles| \quad (Package option)
769 \end{desc}
770
771 \fbox{2.6} Changes the behaviour of the optional argument in
772 sectioning titles so that it sets only the running heads and not the
773 TOC entries, which will be based on the full title.
774
775 \begin{desc}
776 |newlinetospace| \quad (Package option)
777 \end{desc}
778
779 \fbox{2.6} Replaces every occurrence of \verb|\\| or \verb|\\*| in
780 titles by a space in running heads and TOC entries. This way, you do
781 not have to repeat the title just to remove a formatting command. Note
782 with |\chapter| and |\part| you need to set the title class.
783
784 \begin{desc}
785 |notocpart*| \quad (Package option)
786 \end{desc}
787
788 \fbox{2.10.1} Long ago (by the year 2000) I decided for some reason
789 \verb|\part*| would behave like the AMS classes and therefore there
790 should be a contents entry for it. This is somewhat odd, indeed, but
791 the very fact is nobody has complained until now! On the other hand,
792 restoring the behaviour one could expect after 15 years doesn't seem a
793 good idea. This option restores the standard behaviour.
794
795 \subsection{Extended Settings}
796 %~~~~~~~~~~~~~~~~~~~~~~~~~
797
798 The first argument of both |\titleformat| and |\titlespacing| has an
799 extended syntax which
800 allows to set different formats depending on the context.\footnote{%
801 The \textsf{keyval} package is required for making use of it.} This
802 argument can be a list of key/value pairs in the form:
803 \begin{desc}
804 |<key>=<value>, <key>=<value>, <key>, <key>,...|
805 \end{desc}
806 Currently, only pages and unnumbered versions are taken care of,
807 besides the sectioning command name. Thus, the available keys are:
808 \begin{itemize}
809 \item |name|. Allowed values are |\chapter|, |\section|, etc.
810 \item |page|. Allowed values are |odd| or |even|.
811 \item |numberless|. A valueless key. It is not necessary unless you
812 want to set different numbered (without this key) and unnumbered
813 (with |numberless|) variants.
814 \end{itemize}
815 The basic form described above with the name of a sectioning
816 command, say
817 \begin{verbatim}
818 \titleformat{\section} ...
819 \end{verbatim}
820 is in fact an abbreviation for
821 \begin{verbatim}
822 \titleformat{name=\section} ...
823 \end{verbatim}
824
825 Let's suppose we'd like a layout with titles in the
826 outer margin. We might set something like
827 \begin{verbatim}
828 \titleformat{name=\section,page=even}[leftmargin]
829 {\filleft\scshape}{\thesection}{.5em}{}
830
831 \titleformat{name=\section,page=odd}[rightmargin]
832 {\filright\scshape}{\thesection}{.5em}{}
833 \end{verbatim}
834 Since the page information is written to the |aux| file, at
835 least two runs are necessary to get the desired result.
836
837 The ``number'' version is usually fine when generating unnumbered
838 variants since removing the label is the only change required in most
839 cases, but if you need some special formatting, there is the
840 |numberless| key which defines an alternative version for sections
841 without numbers (namely those with level below |secnumdepth|, in the
842 front and back matters and, of course, the starred version). For
843 instance
844 \begin{verbatim}
845 \titleformat{name=\section}{...% The normal definition follows
846 \titleformat{name=\section,numberless}{...% The unnumbered
847 % definition follows
848 \end{verbatim}
849 Neither |<label>| nor |<sep>| are ignored in |numberless|
850 variants.
851
852 These keys are available to both |\titleformat| and
853 |\titlespacing|. By using |page| in one (or both) of them, odd and
854 even pages will be formatted differently. Actually,
855 ``even'' and ``odd'' are well established \LaTeX{} terms, but
856 misleading. In one side printing the ``odd'' pages refer
857 to ``even'' pages as well (cf.\@ |\oddsidemargin|.)
858
859 If you intend to create different odd/even \emph{and}
860 different numbered/unnumbered versions, it is recommended defining
861 the four variants.
862
863 If you remove the page specifier from a sectioning command you
864 must remove the |.aux| file.
865
866 \subsection{Creating new levels and changing the class}
867
868 While the shapes and the like modify the behaviour of titles related
869 to the surrounding text, title classes allow to change the generic
870 behaviour of them. With the help of classes you may insert, say, a
871 new |subchapter| level between |chapter| and |section|, or creating a
872 scheme of your own.
873
874 There are three classes: |page| is like the book |\part|, in a single
875 page, |top| is like |\chapter|, which begins a page and places the
876 title at the top, and |straight| is intended for titles in the middle
877 of text.\footnote{There is an further class named |part| to emulate the
878 article |\cs{part}|, but you should not use it at all. Use the
879 |straight| class instead. Remember some features rely in these classes
880 and \textsf{titlesec} does not change by default the definition of
881 \texttt{\string\part} and \texttt{\string\chapter}.}
882
883 \begin{warning}
884 Making a consistent scheme and defining all of
885 related stuff like counters, macros, format, and spacing is left to the
886 responsibility of the user. If there is a TOC, also the TOC format,
887 which might require redefining the corresponding macros to change the
888 hardcoded value (either by hand or with \textsf{titletoc}).
889 \end{warning}
890
891 \begin{desc}
892 |\titleclass{<name>}{<class>}|\\
893 |\titleclass{<name>}{<class>}[<super-level-cmd>]|
894 \end{desc}
895
896 If you do not use the optional argument, you just change
897 the |<class>| of |<name>|. For example:
898 \begin{verbatim}
899 \titleclass{\part}{straight}
900 \end{verbatim}
901 makes |part| of |straight| class.
902
903 When the second form is used, the level number is the following of
904 |<super-level-cmd>|. For example:
905 \begin{verbatim}
906 \titleclass{\subchapter}{straight}[\chapter]
907 \newcounter{subchapter}
908 \renewcommand{\thesubchapter}{\Alph{subchapter}}
909 \end{verbatim}
910 creates a level under chapter (some additional code is shown as well,
911 but you must add to it the corresponding |\titleformat| and
912 |\titlespacing| settings).\footnote{Regarding counters, the
913 \textsf{remreset} package can be useful.}
914 If the chapter level is 0, then the subchapter one is 1; the levels
915 below are increased by one (section is 2, subsection is 3, and so on).
916
917 There are two sectioning commands which perform some extra actions
918 depending on its name and ignoring the class:
919 \begin{itemize}
920 \item |\chapter| logs the string defined in |\chaptertitlename|
921 and the matter is taken into account.
922 \item |\part| does not encapsulate the label in the toc entry,
923 except if you use the |newparttoc| option.
924 \end{itemize}
925
926 \begin{warning}
927 If you set or reset the class, you may need to redefine the format,
928 too.
929 \end{warning}
930
931 \begin{desc}
932 |loadonly| \quad (Package option)
933 \end{desc}
934
935 Let us suppose you want to create your sectioning commands from scratch.
936 This package option ignores any previous definitions, if any,
937 and hence removes the possibility of using the options described
938 in ``Quick Reference''. Then you use the \textsf{titlesec}
939 tools, and define the corresponding counters and labels.
940
941 \begin{desc}
942 |\titleclass{<name>}[<start-level-num>]{<class>}|
943 \end{desc}
944
945 Here, the |<name>| title is considered the top level, with number
946 |<start-level-num>| (typically 0 or $-$1). It should be used only when
947 creating sectioning commands from scratch with the help of |loadonly|,
948 and there must be exactly one (no more, no less) declaration of this
949 kind. After it, the rest of levels are added as explained above.
950
951 \section{Additional Notes}
952 %~~~~~~~~~~~~~~~~~~~~~~~~
953
954 Only a |\footnote| command is allowed in titles, but it will work.
955 However, the footnote mark is not removed from toc entries or running
956 headings; for that use
957 \begin{verbatim}
958 \usepackage[stable]{footmisc}
959 \end{verbatim}
960
961 The rest of this section describes briefly some \LaTeX{} commands,
962 useful when defining sectioning titles.
963
964 \subsection{Fixed Width Labels}
965
966 The |\makebox| command allows to use fixed width label, which
967 makes the left margin of the actual title (not the label) to lie
968 in the same place. For instance (only the relevant code is
969 provided):
970 \begin{verbatim}
971 \titleformat{\section}
972 {..}
973 {\makebox[2em]{\thesection}}{..}{..}
974 \end{verbatim}
975
976 See your \LaTeX{} manual for further reference on boxing commands.
977
978 \subsection{Starred Versions}
979 \label{s:starred}
980
981 Using sectioning commands in the starred version is strongly
982 discouraged. Instead, you can use a set of markup oriented commands
983 which are easy to define and modify, if necessary. Thus, you can test
984 different layouts before choosing amongst them.
985
986 Firstly remember if you say
987 \begin{verbatim}
988 \setcounter{secnumdepth}{0}
989 \end{verbatim}
990 sections will not be numbered but they will be included in both toc
991 and headers.
992
993 Now, let's
994 suppose you want to include some sections with a special content;
995 for example, a section (or more) with exercises. We will use an
996 environment named |exercises| whose usage is:
997 \begin{verbatim}
998 \section{A section}
999 Text of a normal section.
1000
1001 \begin{exercises}
1002 \section{Exercises A}
1003 Some exercises
1004
1005 \section{Exercises B}
1006 Some exercises
1007 \end{exercises}
1008 \end{verbatim}
1009
1010 The following definition suppresses numbers but neither toc lines
1011 nor headers.
1012 \begin{verbatim}
1013 \newenvironment{exercises}
1014 {\setcounter{secnumdepth}{0}}
1015 {\setcounter{secnumdepth}{2}}
1016 \end{verbatim}
1017
1018 The following one adds a toc line but headers will remain
1019 untouched:
1020 \begin{verbatim}
1021 \newenvironment{exercises}
1022 {\setcounter{secnumdepth}{0}%
1023 \renewcommand\sectionmark[1]{}}
1024 {\setcounter{secnumdepth}{2}}
1025 \end{verbatim}
1026
1027 The following one updates the headers but there will be
1028 no toc line:
1029 \begin{verbatim}
1030 \newenvironment{exercises}
1031 {\setcounter{secnumdepth}{0}%
1032 \addtocontents{toc}{\protect\setcounter{tocdepth}{0}\ignorespaces}}
1033 {\setcounter{secnumdepth}{2}%
1034 \addtocontents{toc}{\protect\setcounter{tocdepth}{2}\ignorespaces}}
1035 \end{verbatim}
1036 (I find the latter a bit odd in this particular example; the
1037 first and second options are more sensible. The |\ignorespaces|
1038 is not very important, and you need not it unless there is
1039 unwanted space in the toc.)
1040
1041 That works with standard classes, but if you are using
1042 \textsf{fancyhdr} or \textsf{titlesec} to define headers you need
1043 further refinement to kill the section number. In \textsf{titlesec}
1044 that's accomplished with |\ifthesection| (see \textsf{titleps.pdf}).
1045
1046 As you can see, there are no |\addcontentsline|, no |\markboth|, no
1047 |\section*|, just logical structure. Of course you may change it as you
1048 wish; for example if you decide these sections should be typeset in
1049 small typeface, include |\small|, and if you realize you do not like
1050 that, remove it.
1051
1052 While the standard \LaTeX{} commands are easier and more
1053 direct for simple cases, I think the proposed method above is
1054 far preferable in large documents.
1055
1056 \subsection{Variants}
1057
1058 Let's suppose we want to mark some sections as ``advanced topics''
1059 with an asterisk after the label.
1060 The following code does the job:
1061 \begin{verbatim}
1062 \newcommand{\secmark}{}
1063 \newenvironment{advanced}
1064 {\renewcommand{\secmark}{*}}
1065 {}
1066 \titleformat{\section}
1067 {..}
1068 {\thesection\secmark\quad}{..}{..}
1069 \end{verbatim}
1070
1071 To mark the sections write
1072 \begin{verbatim}
1073 \begin{advanced}
1074 \section{...}
1075 ...
1076 \end{advanced}
1077 \end{verbatim}
1078
1079 That marks sections but not subsections. If you like being
1080 redundant and marking the subsection level as well, you must
1081 define it accordingly.
1082
1083 \subsection{Putting a Dot after the Section Title}
1084 \label{sec:dotafter}
1085
1086 Today this styling is not used, but formerly it was fairly common.
1087 The basic technique was described above, but here is a reminder:
1088 \begin{verbatim}
1089 \newcommand{\periodafter}[1]{#1.}
1090 \titleformat{\section}
1091 {..}
1092 {\thesection}{..}{..\periodafter}
1093 \end{verbatim}
1094
1095 If you had to combine this dot with some command (perhaps an
1096 underlining), you can say:
1097 \begin{verbatim}
1098 \newcommand{\periodafter}[2]{#1{#2.}}
1099 \titleformat{\section}
1100 {..}
1101 {\thesection}{..}{..\periodafter{\ul}} % \ul from soul package
1102 \end{verbatim}
1103
1104 However, you might prefer the package option \texttt{explicit}.
1105
1106 \section{\textsf{titleps} and Page Styles}
1107 %~~~~~~~~~~~~~~~~~~~
1108
1109 The \textsf{titleps} package provides tools for one-stage setting of
1110 page styles (headlines and footlines). A higher-level interface is
1111 used, where the mark mechanism is hidden and there is no need to deal
1112 with |\leftmark|s and |\rightmark|s -- just use a command or variable
1113 registered as a ``mark'' as the expected value will be returned, i.e.,
1114 those when the mark was emitted, either by a sectioning command or
1115 explicitly with |\chaptermark|, |\sectionmark|, etc. A simple
1116 example, whose meaning should be obvious, is:
1117 \begin{verbatim}
1118 \newpagestyle{main}{
1119 \sethead[\thepage][\chaptertitle][(\thesection] % even
1120 {\thesection)}{\sectiontitle}{\thepage}} % odd
1121 \pagestyle{main}
1122 \end{verbatim}
1123
1124 Other features are:
1125 \begin{itemize}
1126 \item Working top marks, compatible with floats (unlike the standard
1127 |\topmark|, which does not work correctly in \LaTeX{}).
1128 \item Access to top, first and bot marks in a single headline/footline
1129 (e.g., the first and last section numbers).
1130 \item Marks for more than 2 sectioning levels.
1131 \item Simple (and not so simple) headrules and footrules.
1132 \item Headlines and footlines for pages with floats.
1133 \item Headlines and footlines for specific floats (a sort of
1134 |\thispagestyle| for floats).
1135 \item Multiple sets of marks (named here \emph{markset}s and
1136 \textit{extra marks}).
1137 \end{itemize}
1138
1139 It can be used without \textsf{titlesec}, but you will get most of
1140 it when used together. To load it as a separate package, use the
1141 customary \verb|\usepackage{titleps}|, but with \textsf{titlesec} you
1142 have to load it with:
1143 \begin{verbatim}
1144 \usepackage[pagestyles]{titlesec}
1145 \end{verbatim}
1146
1147 Please, read |titleps.pdf| (or typeset |titleps.tex|) for further
1148 information.
1149
1150 \section{Contents: The \textsf{titletoc} package}
1151 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1152
1153 This package is a companion to the \textsf{titlesec} package and it
1154 handles
1155 toc entries. However, it is an independent package and you can use
1156 it alone. The philosophy is similar to that of \textsf{titlesec}---instead
1157 of hooking the commands as defined by standard \LaTeX{} and classes,
1158 there are new commands which you can format the toc entries with
1159 in a generic way. This means you have to learn just
1160 two new basic command and a couple of tools, no more, and you have access
1161 to
1162 new features. Paragraph format
1163 and fonts are set with commands like |\\|,
1164 |\makebox|,
1165 |\large|, |\itshape|, and so on, and entries are not shaped in any
1166 fashion because they are pretty free form.
1167
1168 The behaviour of entries
1169 defined with \textsf{titletoc} are different at some points
1170 to those created with the standard commands. In particular:
1171 \begin{itemize}
1172 \item Pages are never broken between entries if the first one is
1173 of an higher level than the second one as, for instance, between
1174 a section and a subsection. If both of them are of the same
1175 level, the break is allowed, and if the first is lower than
1176 the second, it is considered a good place for a page break.
1177
1178 \item The symbols in the leaders are not centered but flushed
1179 right. That is usually more convenient.
1180 \end{itemize}
1181
1182 I would like to note no attempt to handle tocs can be complete
1183 because the standard \LaTeX{} commands write directly some formatting
1184 commands which cannot be removed. This is particularly important in
1185 lists of figures and tables, and in the |\part| command.\footnote{But
1186 some of these issues are fixed by \textsf{titlesec}.}
1187
1188 \subsection{A ten-minute guide to \textsf{titletoc}}
1189
1190 Toc entries are treated as rectangular areas where the text
1191 and probably a filler will be written. Let's draw such an
1192 area (of course, the lines themselves are not printed):
1193 \setlength{\unitlength}{1cm}
1194 \begin{center}
1195 \begin{picture}(8,2.2)
1196 \put(1,1){\line(1,0){6}}
1197 \put(1,2){\line(1,0){6}}
1198 \put(1,1){\line(0,1){1}}
1199 \put(7,1){\line(0,1){1}}
1200 \put(0,.7){\vector(1,0){1}}
1201 \put(8,.7){\vector(-1,0){1}}
1202 \put(0,.2){\makebox(1,.5)[b]{\textit{left}}}
1203 \put(7,.2){\makebox(1,.5)[b]{\textit{right}}}
1204 \end{picture}
1205 \end{center}
1206
1207 The space between the left page margin and the left edge of
1208 the area will be named |<left>|; similarly we have |<right>|.
1209 You are allowed to modify the beginning of the first line and
1210 the ending of the last line. For example by ``taking up'' both
1211 places with |\hspace*{2pc}| the area becomes:
1212 \begin{center}
1213 \begin{picture}(8,2.2)
1214 \put(1,1){\line(1,0){5.5}}
1215 \put(6.5,1){\line(0,1){.5}}
1216 \put(6.5,1.5){\line(1,0){.5}}
1217 \put(1.5,2){\line(1,0){5.5}}
1218 \put(1,1.5){\line(1,0){.5}}
1219 \put(1.5,1.5){\line(0,1){.5}}
1220 \put(1,1){\line(0,1){.5}}
1221 \put(7,1.5){\line(0,1){.5}}
1222 \put(0,.7){\vector(1,0){1}}
1223 \put(8,.7){\vector(-1,0){1}}
1224 \put(0,.2){\makebox(1,.5)[b]{\textit{left}}}
1225 \put(7,.2){\makebox(1,.5)[b]{\textit{right}}}
1226 \end{picture}
1227 \end{center}
1228 And by ``clearing'' space in both places with |\hspace*{-2pc}|
1229 the area becomes:
1230 \begin{center}
1231 \begin{picture}(8,2.2)
1232 \put(1,1){\line(1,0){6.5}}
1233 \put(7.5,1){\line(0,1){.5}}
1234 \put(7.5,1.5){\line(-1,0){.5}}
1235 \put(.5,2){\line(1,0){6.5}}
1236 \put(1,1.5){\line(-1,0){.5}}
1237 \put(.5,1.5){\line(0,1){.5}}
1238 \put(1,1){\line(0,1){.5}}
1239 \put(7,1.5){\line(0,1){.5}}
1240 \put(0,.7){\vector(1,0){1}}
1241 \put(8,.7){\vector(-1,0){1}}
1242 \put(0,.2){\makebox(1,.5)[b]{\textit{left}}}
1243 \put(7,.2){\makebox(1,.5)[b]{\textit{right}}}
1244 \end{picture}
1245 \end{center}
1246
1247 If you have seen tocs, the latter should be familiar to you--
1248 the label at the very beginning, the page at the very end:
1249 \begin{verbatim}
1250 3.2 This is an example showing that toc
1251 entries fits in that scheme . . . . 4
1252 \end{verbatim}
1253
1254 All you need is to put these elements in the right way. If you have
1255 reserved the space with |\hspace*{-2pc}|, simply put a box 2 pc
1256 width
1257 containing the section label or page so that this space will be
1258 retrieved; this layout is used so often that two commands are provided
1259 which does that for you:
1260 \begin{itemize}
1261 \item |\contentslabel{<length>}| creates the space at the beginning
1262 and
1263 prints the section number.
1264 \item |\contentspage| creates a space at the end of length |<right>|
1265 and prints the page number aligned at the right.
1266 \end{itemize}
1267
1268 Now, we are about to show the three basic commands:
1269
1270 \begin{desc}
1271 |\dottedcontents{<section>}[<left>]{<above-code>}|\\
1272 | {<label width>}{<leader width>}|
1273 \end{desc}
1274
1275 Here:
1276 \begin{itemize}
1277 \item |<section>| is the section name without backslash: |part|,
1278 |chapter|, |section|, etc. |figure| and |table| are allowed, too.
1279 (The backlash is omitted because we are dealing with the concept
1280 and not the |\part|, |\section|, etc. macros themselves.
1281 Furthermore, |figure| and |table| are environments.)
1282
1283 \item |<above-code>| is code for the global formatting of the entry.
1284 Vertical material is allowed. At this point the value of
1285 |\thecontentslabel| (see below) is known which enables you to
1286 take decisions depending on its value (with the help of
1287 the \textsf{ifthen} package). You may use the \textsf{titlesec}
1288 |\filleft|, |\filright|, |\filcenter| and |\fillast| commands.
1289
1290 \item |<left>| even if bracketed is currently mandatory and it
1291 sets the left margin from the left page margin.
1292
1293 \item |<label width>| is the width of the space created for the label,
1294 as described above.
1295
1296 \item |<leader width>| is the width of the box containing the char to
1297 be used as filler, as described below.
1298 \end{itemize}
1299
1300 The definitions for section and subsection entries in the \textsf{book}
1301 class are roughly equivalent to:
1302 \begin{verbatim}
1303 \contentsmargin{2.55em}
1304 \dottedcontents{section}[3.8em]{}{2.3em}{1pc}
1305 \dottedcontents{subsection}[6.1em]{}{3.2em}{1pc}
1306 \end{verbatim}
1307
1308 \begin{desc}
1309 |\titlecontents{<section>}[<left>]{<above-code>}|\\
1310 | {<numbered-entry-format>}{<numberless-entry-format>}|\\
1311 | {<filler-page-format>}[<below-code>]|
1312 \end{desc}
1313
1314 Here |<section>|, |<left>| and |<above-code>| like above, and
1315 \begin{itemize}
1316 \item |<numbered-entry-format>| is in horizontal mode and it will
1317 be used just before the entry title. As in |\titleformat|, the
1318 last command can take an argument with the title.
1319
1320 \item |<numberless-entry-format>| is like the above if there is, well,
1321 no label.
1322
1323 \item|<filler-page-format>| is self explanatory. Fillers are created
1324 with the |\titlerule| command which is shared by that package and
1325 \textsf{titlesec}. However, when used in this context its behaviour
1326 changes a little to fit the needs of toc leaders.\footnote{For
1327 \TeX{}nicians, the default |\cs{xleaders}| becomes
1328 |\cs{leaders}|.} You might prefer a |\hspace| instead.
1329
1330 \item And finally |<below-code>| is code following the entry for, say,
1331 vertical space.
1332 \end{itemize}
1333
1334 When defining entries, use |\addvspace| if you want to add vertical
1335 space, and |\\*| instead of |\\| for line breaks.
1336
1337 This command can be used in the middle of a document to change
1338 the format of toc/lot/lof entries at any point. The new format is
1339 written to the toc file and hence two runs are necessary to
1340 see the changes.
1341
1342 \begin{desc}
1343 |\contentsmargin{<right>}|
1344 \end{desc}
1345
1346 The value set is used in all of sections. If you are wondering
1347 why, the answer is quite simple: in most of cases the |<right>|
1348 margin will be constant. However, you are allowed to change
1349 it locally in the |<above-code>| arguments. Note as well that
1350 the default space in standard classes does not leave room to
1351 display boldfaced page number above 100 and therefore you
1352 might want to set a larger margin with this command.
1353
1354 The \textsf{book} class formats section entries
1355 similarly (but not equally) to:
1356 \begin{verbatim}
1357 \titlecontents{section}
1358 [3.8em] % ie, 1.5em (chapter) + 2.3em
1359 {}
1360 {\contentslabel{2.3em}}
1361 {\hspace*{-2.3em}}
1362 {\titlerule*[1pc]{.}\contentspage}
1363 \end{verbatim}
1364 Compare this definition with that given above and you will
1365 understand how |\dottedcontents| is defined.
1366
1367 Although standard classes use font dependent units (mainly em), with
1368 |titletoc| you have to use absolute ones (pc, pt, etc.) to ensure they
1369 entries are aligned correctly.
1370
1371 \subsection{And more}
1372
1373 Strict typographical rules state full text lines shouldn't
1374 surpass the last dot of the leaders; ideally they should be aligned.
1375 Surprisingly enough, \TeX{} lacks of a tool for doing that
1376 automatically---when you fill a box with leading dots, they can be
1377 centered in the box with the |\cleaders| primitive , ``justified''
1378 with |\xleaders| or aligned with the outermost enclosing box with
1379 |\leaders|, but there is no way to align them with the ``current''
1380 margin.
1381
1382 So, the only way to get a fine layout is by hand. To do , you can
1383 use the an optional argument in the |\contentsmargin| command whose
1384 syntax in full is the following:
1385 \begin{desc}
1386 |\contentsmargin[<correction>]{<right>}|
1387 \end{desc}
1388
1389 The |<correction>| length is added to the |<right>| one in all of lines
1390 except the last one, where the leaders are placed. For instance, if
1391 the text lines are 6 pt longer than the last dot, you should rewrite the
1392 |\contentsmargin| command to add a |<correction>| of 6 pt.%
1393 \footnote{Usefully, many dvi previewers allow to get the coordinates of
1394 the pointed location.} Unlike the standard \LaTeX{} tools, the
1395 |\titlerule*| command has been designed so that the |<correction>|
1396 will have the minimum value possible.
1397
1398 \begin{desc}
1399 |\thecontentslabel \thecontentspage|
1400 \end{desc}
1401
1402 Contains the text with the label and the page with no additional
1403 formatting, except written by the class.
1404
1405 \begin{desc}
1406 |\contentslabel[<format>]{<space>}|\\
1407 |\contentspage[<format>]|
1408 \end{desc}
1409
1410 As described above, but with different |<format>|s. The defaults are
1411 just |\thecontentslabel| and |\thecontentspage|, respectively.
1412
1413 \begin{desc}
1414 |\contentspush{<text>}|
1415 \end{desc}
1416
1417 Prints the |<text>| and increases
1418 |<left>| by the width of |<text>|. It is similar to
1419 the hang shape of \textsf{titlesec}.
1420
1421 \begin{desc}
1422 |\titlecontents*{<section>}[<left>]{<above-code>}|\\
1423 | {<numbered-entry-format>}{<numberless-entry-format>}|\\
1424 | {<filler-page-format>}[<separator>]|\\[3pt]
1425 | |\textit{or ...}|{<filler-page-format>}[<separator>][<end>]|\\
1426 | |\textit{or ...}|{<filler-page-format>}[<begin>][<separator>][<end>]|
1427 \end{desc}
1428
1429 This starred version groups the entries in a single paragraph.
1430 The |<separator>| argument is the separator between entries, and
1431 there is a further optional argument with an ending
1432 punctuation. For example, this document sets:
1433 \begin{verbatim}
1434 \titlecontents*{subsection}[1.5em]
1435 {\small}
1436 {\thecontentslabel. }
1437 {}
1438 {, \thecontentspage}
1439 [.---][.]
1440 \end{verbatim}
1441 whose result is showed in the contents at the very beginning of
1442 this document. Note the paragraph format must be written in
1443 the |<above-code>| argument.
1444
1445 Let us explain how the optional arguments works. First note the number
1446 of them determines their meaning---since there should be a separator
1447 between entries this one is always present; on the other hand,
1448 |<begin>| is rarely used and hence it has the lowest ``preference.''
1449 The simplest case is when the titles are of the same level; in this
1450 case the |<sepatator>| and the |<end>| parameters (which default to
1451 empty) are inserted between consecutive entries and at the end of the
1452 block, respectively. |<before-code>| is executed just once at the
1453 very beginning of the block and its declarations are local to the
1454 whole set of entries.
1455
1456 Now suppose we want to group entries of two levels; in this
1457 case a nesting principle applies. To fix ideas, we will use section
1458 and subsection. When a subsection entry begins after a section one,
1459 |<before-code>| is executed and |<begin>| of subsection is
1460 inserted, which should contain text format only. Then subsections are
1461 added inserting separators as explained above. When a section
1462 arrives, the ending punctuation of subsection and the separator of
1463 section is added (except if the block is finished by a subsection,
1464 where the ending of section is added instead). We said ``after a
1465 section'' because a subsection never begins a block.\footnote{In rare
1466 cases that could be necessary, yet.} The
1467 subsection entries are nested inside the section ones, and
1468 declarations are again local.
1469
1470 An example will illustrate that.
1471 \begin{verbatim}
1472 \titlecontents*{section}[0pt]
1473 {\small\itshape}{}{}
1474 {}[ \textbullet\ ][.]
1475
1476 \titlecontents*{subsection}[0pt]
1477 {\upshape}{}{}
1478 {, \thecontentspage}[ (][. ][)]
1479 \end{verbatim}
1480 produces something similar to:
1481 $$\begin{minipage}{\textwidth}
1482 \small\itshape The first section \textbullet\ The second one \textbullet\
1483 The third one {\upshape(A subsection in it, 1. Another, 2)} \textbullet\ A
1484 fourth section {\upshape(A subsection in it, 1. Another, 2)}.
1485 \end{minipage}$$
1486
1487 \begin{desc}
1488 |\contentsuse{<name>}{<ext>}|
1489 \end{desc}
1490
1491 Makes \textsf{titletoc} aware of the existence of a contents file with
1492 |<ext>| extension. Mainly, it makes sure the command
1493 |\contentsfinish| is added at the end of the corresponding
1494 contents (and which must be added at the end of tocs made by hand).
1495 The package performs
1496 \begin{verbatim}
1497 \contentsuse{figure}{lof}
1498 \contentsuse{table}{lot}
1499 \end{verbatim}
1500
1501 % \begin{desc}
1502 % |\titlelevels{<top>}{<level-list>}|
1503 % \end{desc}
1504 %
1505 % If you are not using \textsf{titlesec}, this command modifies
1506 % the list of level names. Only necessary if you have been devised
1507 % your own scheme of titles.
1508
1509 \begin{desc}
1510 |leftlabels rightlabels| \quad (Package options)
1511 \end{desc}
1512
1513 These package options set how the labels are aligned in
1514 |\contentslabel|.
1515 Default is |rightlabels|. With |leftlabels| the default |<format>| for
1516 |\contentslabel| becomes |\thecontenstlabel\enspace|.
1517
1518 \begin{desc}
1519 |dotinlabels| \quad (Package option)
1520 \end{desc}
1521
1522 With this package option, a dot is added after the label in
1523 |\contentslabel|.
1524
1525 \subsection{Partial TOC's}
1526
1527 \begin{desc}
1528 |\startcontents[<name>]|
1529 \end{desc}
1530
1531 At the point where this command is used, a partial toc begins (note
1532 the document doesn't require a |\tableofcontents| for partial tocs to
1533 work). The |<name>| argument allows different sets of tocs and it
1534 defaults to |default|. These sets may be intermingled, but usually
1535 will be nested. For example, you may want two kinds of partial tocs:
1536 by part and by chapter (besides the full toc, of course). When a part
1537 begins, write |\startcontents[parts]|, and when a chapter
1538 |\startcontents[chapters]|. This way a new toc is started at each
1539 part and chapter.\footnote{\emph{All} partial tocs are stored in a
1540 single file with extension |.ptc|.}
1541
1542 \begin{desc}
1543 |\stopcontents[<name>]|\\
1544 |\resumecontents[<name>]|
1545 \end{desc}
1546
1547 Stops the partial toc of |<name>| kind, which may be resumed.
1548 Since partial contents are stopped by |\startcontents| if necessary,
1549 those macros will not be used very often.
1550
1551 \begin{desc}
1552 |\printcontents[<name>]{<prefix>}{<start-level>}[<toc-depth>]{<toc-code>}|
1553 \end{desc}
1554
1555 Print the current partial toc of |<name>| kind. The format
1556 of the main toc entries are used, except if there is a |<prefix>|.
1557 In such a case, the format of |<prefix><level>| is used, provided
1558 it is defined. For example, if prefix is |l| and the format of
1559 |lsection| is defined, then this definition will be used; otherwise,
1560 the format is that of |section|. The |<start-level>| parameter sets the
1561 top level of the tocs---for a part toc it would be |0| (chapter), for a
1562 chapter toc |1| (section), and so on. The |<toc-code>| is
1563 local code for the current toc; it may be used to change the
1564 |\contentsmargin|, for instance. \textbf{New 2.11} Finally,
1565 |<toc-depth>| sets the |tocdepth| locally (in former versions it was
1566 suggested setting this value with |\setcounter| in the last argument,
1567 but that was wrong, because this command set counters globally).
1568
1569 A simple usage might look like (provided you are using
1570 \textsf{titlesec} as well):
1571 \begin{verbatim}
1572 \titleformat{\chapter}[display]
1573 {...}{...}{...} % Your definitions come here
1574 [{\vspace*{4pc}%
1575 \startcontents
1576 \printcontents{l}{1}[2]{}}]
1577
1578 \titlecontents*{lsection}[0pt]
1579 {\small\itshape}{}{}
1580 {}[ \textbullet\ ][.]
1581 \end{verbatim}
1582 The included entries are those in levels 1 to 2 inclusive (i.e., 1
1583 and 2). Note the whole optional argument is enclosed in braces, because
1584 there is an internal \texttt{[]}.
1585
1586 \subsection[Partial lists]{Partial lists \normalfont\normalsize\fbox{2.6}}
1587
1588 You may want to create partial LOFs and LOTs. The systax is similar to
1589 that of partial TOCs and what was said for them can be applied here.
1590 The commands are:
1591 \begin{desc}
1592 |\startlist[<name>]{<list>}|\\
1593 |\stoplist[<name>]{<list>}|\\
1594 |\resumelist[<name>]{<list>}|\\
1595 |\printlist[<name>]{<list>}{<prefix>}[<toc-depth>]{<toc-code>}|
1596 \end{desc}
1597
1598 Here |<list>| is either |lof| or |lot|. Note as well |\printlist|
1599 does not have the |<start-level>| argument, because figures and tables
1600 have not levels. Currently, only those two float lists are supported,
1601 but in a future release support for more kinds of float lists will be
1602 added. Unfortunately, many classes write some formatting commands to
1603 these lists (more precisely, \verb|\addvspace|s in chapters); I'm
1604 still not sure how to remove these commands without removing as well
1605 others which can be wanted, but for the time being a quick trick to
1606 remove these spaces is to redefine \verb|\addvspace| in the
1607 |<toc-code>| with |\renewcommand\addvspace[1]{}|.
1608
1609 \subsection{Examples}
1610
1611 \begin{verbatim}
1612 \titlecontents{chapter}
1613 [0pt]
1614 {\addvspace{1pc}%
1615 \itshape}%
1616 {\contentsmargin{0pt}%
1617 \bfseries
1618 \makebox[0pt][r]{\huge\thecontentslabel\enspace}%
1619 \large}
1620 {\contentsmargin{0pt}%
1621 \large}
1622 {\quad\thepage}
1623 [\addvspace{.5pc}]
1624 \end{verbatim}
1625
1626 The chapter number is out at the edge of the page margin, in a font
1627 larger than the font of the title. If the chapter lacks of number
1628 (because, say, it is the preface or the bibliography) it is not
1629 boldfaced. The page number follows the title without fillers, but
1630 after an em-space.
1631
1632 \begin{verbatim}
1633 \titlecontents{chapter}
1634 [3pc]
1635 {\addvspace{1.5pc}%
1636 \filcenter}
1637 {CHAPTER \thecontentslabel\\*[.2pc]%
1638 \huge}
1639 {\huge}
1640 {} % That is, without page number
1641 [\addvspace{.5pc}]
1642 \end{verbatim}
1643
1644 The chapter title is centered with the chapter label on top
1645 of it. There is no page number.
1646
1647 \subsection{Inserting a figure in the contents}
1648
1649 The |\addtocontents| command is still available and you may use
1650 it to perform special operation, like inserting a figure just before
1651 or after of an entry. Sadly, fragile
1652 arguments are not allowed and writing complex code could be a mess.
1653 The trick is to define a command to perform the required operations
1654 which in turn is written with |\protect|.
1655
1656 Let's suppose we want to insert a figure before an entry.
1657 \begin{verbatim}
1658 \newcommand{\figureintoc}[1]{
1659 \begin{figure}
1660 \includegraphics{#1}%
1661 \end{figure}}
1662 \end{verbatim}
1663 makes the dirty work.
1664
1665 In the place where a figure is inserted write:
1666 \begin{verbatim}
1667 \addtocontents{\protect\figureintoc{myfig}}
1668 \end{verbatim}
1669
1670 \subsection{Marking entries with asterisks}
1671
1672 Let's now resume a problem explained in relation with
1673 \textsf{titlesec}: marking sections with asterisks to
1674 denote an ``advanced topic'' unless the star should
1675 be printed in the toc as well. Here is the code:
1676 \begin{verbatim}
1677 \newcommand{\secmark}{}
1678 \newcommand{\marktotoc}[1]{\renewcommand{\secmark}{#1}}
1679 \newenvironment{advanced}
1680 {\renewcommand{\secmark}{*}%
1681 \addtocontents{toc}{\protect\marktotoc{*}}}
1682 {\addtocontents{toc}{\protect\marktotoc{}}}
1683 \titleformat{\section}
1684 {..}
1685 {\thesection\secmark}{..}{..}
1686 \titlecontents{section}[..]{..}
1687 {\contentslabel[\thecontentslabel\secmark]{1.5pc}}{..}{..}
1688 \end{verbatim}
1689
1690 \section{The \textsf{titlesec} philosophy}
1691
1692 Once you have read the documentation it should be clear this
1693 is not a package for the casual user who likes the standard
1694 layout and wants to make simple changes. This is a tool for the
1695 serious typographer who has a clear idea of what layout he wants
1696 but does not have the skill to get it. No attempt is made to improve
1697 your taste in section formatting.
1698
1699 \section{Appendix}
1700
1701 The following examples will be illustrative. In this part, the
1702 |\parskip| is 0 pt.
1703
1704 \begingroup
1705
1706 \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}\ignorespaces}
1707 \setlength{\parskip}{0pt}
1708
1709 \examplesep
1710
1711 \titleformat{\section}[block]
1712 {\normalfont\bfseries\filcenter}{\fbox{\itshape\thesection}}{1em}{}
1713
1714 \section[Appendix]{This is an
1715 example of the section command defined below and, what's more, this
1716 is an example of the section command defined below}
1717
1718 \begin{verbatim}
1719 \titleformat{\section}[block]
1720 {\normalfont\bfseries\filcenter}{\fbox{\itshape\thesection}}{1em}{}
1721 \end{verbatim}
1722
1723 \examplesep
1724
1725 \titleformat{\section}[frame]
1726 {\normalfont}
1727 {\filright
1728 \footnotesize
1729 \enspace SECTION \thesection\enspace}
1730 {8pt}
1731 {\Large\bfseries\filcenter}
1732
1733 \section[Appendix]{A framed title}
1734
1735 \begin{verbatim}
1736 \titleformat{\section}[frame]
1737 {\normalfont}
1738 {\filright
1739 \footnotesize
1740 \enspace SECTION \thesection\enspace}
1741 {8pt}
1742 {\Large\bfseries\filcenter}
1743 \end{verbatim}
1744
1745 \examplesep
1746
1747 \titleformat{\section}
1748 {\titlerule
1749 \vspace{.8ex}%
1750 \normalfont\itshape}
1751 {\thesection.}{.5em}{}
1752
1753 \section[Appendix]{A Ruled Title}
1754
1755 \begin{verbatim}
1756 \titleformat{\section}
1757 {\titlerule
1758 \vspace{.8ex}%
1759 \normalfont\itshape}
1760 {\thesection.}{.5em}{}
1761 \end{verbatim}
1762
1763 \examplesep
1764
1765 \titleformat{\section}[block]
1766 {\normalfont\sffamily}
1767 {\thesection}{.5em}{\titlerule\\[.8ex]\bfseries}
1768
1769 \section[Appendix]{Another Ruled Title}
1770
1771 \begin{verbatim}
1772 \titleformat{\section}[block]
1773 {\normalfont\sffamily}
1774 {\thesection}{.5em}{\titlerule\\[.8ex]\bfseries}
1775 \end{verbatim}
1776
1777 \examplesep
1778
1779 \titleformat{\section}[block]
1780 {\filcenter\large
1781 \addtolength{\titlewidth}{2pc}%
1782 \titleline*[c]{\titlerule*[.6pc]{\tiny\textbullet}}%
1783 \addvspace{6pt}%
1784 \normalfont\sffamily}
1785 {\thesection}{1em}{}
1786 \titlespacing{\section}
1787 {5pc}{*2}{*2}[5pc]
1788
1789 \section[Appendix]{The length of the ``rule'' above
1790 is that of the longest line in this title increased by
1791 two picas}
1792
1793 \leavevmode
1794
1795 \section[Appendix]{This one is shorter}
1796
1797 \begin{verbatim}
1798 \titleformat{\section}[block]
1799 {\filcenter\large
1800 \addtolength{\titlewidth}{2pc}%
1801 \titleline*[c]{\titlerule*[.6pc]{\tiny\textbullet}}%
1802 \addvspace{6pt}%
1803 \normalfont\sffamily}
1804 {\thesection}{1em}{}
1805 \titlespacing{\section}
1806 {5pc}{*2}{*2}[5pc]
1807 \end{verbatim}
1808
1809 \examplesep
1810
1811 \titleformat{\section}[display]
1812 {\normalfont\fillast}
1813 {\scshape section \oldstylenums{\thesection}}
1814 {1ex minus .1ex}
1815 {\small}
1816 \titlespacing{\section}
1817 {3pc}{*3}{*2}[3pc]
1818
1819 \section[Appendix]{This is an example of the section
1820 command defined below
1821 and, what's more, this is
1822 an example of the section command defined below. Let us repeat it.
1823 This is an example of the section command defined below
1824 and, what's more, this is
1825 an example of the section command defined below}
1826
1827 \begin{verbatim}
1828 \titleformat{\section}[display]
1829 {\normalfont\fillast}
1830 {\scshape section \oldstylenums{\thesection}}
1831 {1ex minus .1ex}
1832 {\small}
1833 \titlespacing{\section}
1834 {3pc}{*3}{*2}[3pc]
1835 \end{verbatim}
1836
1837 \examplesep
1838
1839 \titleformat{\section}[runin]
1840 {\normalfont\scshape}
1841 {}{0pt}{}
1842 \titlespacing{\section}
1843 {\parindent}{*2}{\wordsep}
1844
1845 \section*{This part is the title itself}
1846 and this part is the section body\ldots
1847
1848 \begin{verbatim}
1849 \titleformat{\section}[runin]
1850 {\normalfont\scshape}
1851 {}{0pt}{}
1852 \titlespacing{\section}
1853 {\parindent}{*2}{\wordsep}
1854 \end{verbatim}
1855
1856 \examplesep
1857
1858 \titleformat{\section}[wrap]
1859 {\normalfont\fontseries{b}\selectfont\filright}
1860 {\thesection.}{.5em}{}
1861 \titlespacing{\section}
1862 {12pc}{1.5ex plus .1ex minus .2ex}{1pc}
1863
1864 \section[Appendix]{A Simple Example of the
1865 ``wrap'' Section Shape}
1866
1867 Which is followed by some text to show the result. Which is followed
1868 by some text to show the result. Which is followed by some text to
1869 show the result. Which is followed by some text to show the result.
1870 Which is followed by some text to show the result. Which is followed
1871 by some text to show the result. Which is followed
1872 by some text to show the result.
1873
1874 \section[Appendix]{And another}
1875
1876 Note how the text wraps the title and the space reserved to it is
1877 readjusted automatically. And it is followed by some text to
1878 show the result. Which is followed by some text to show the result.
1879
1880 \begin{verbatim}
1881 \titleformat{\section}[wrap]
1882 {\normalfont\fontseries{b}\selectfont\filright}
1883 {\thesection.}{.5em}{}
1884 \titlespacing{\section}
1885 {12pc}{1.5ex plus .1ex minus .2ex}{1pc}
1886 \end{verbatim}
1887
1888 \examplesep
1889
1890 \titleformat{\section}[runin]
1891 {\normalfont\bfseries}
1892 {\S\ \thesection.}{.5em}{}[.---]
1893 \titlespacing{\section}
1894 {\parindent}{1.5ex plus .1ex minus .2ex}{0pt}
1895
1896 \section[Appendix]{Old-fashioned runin title}
1897
1898 Of course, you would prefer just a dot after the title. In
1899 this case the optional argument should be |[.]| and the space
1900 after a sensible value (1em, for example).
1901
1902 \begin{verbatim}
1903 \titleformat{\section}[runin]
1904 {\normalfont\bfseries}
1905 {\S\ \thesection.}{.5em}{}[.---]
1906 \titlespacing{\section}
1907 {\parindent}{1.5ex plus .1ex minus .2ex}{0pt}
1908 \end{verbatim}
1909
1910 \examplesep
1911
1912 \titleformat{\section}[leftmargin]
1913 {\normalfont
1914 \titlerule*[.6em]{\bfseries .}%
1915 \vspace{6pt}%
1916 \sffamily\bfseries\filleft}
1917 {\thesection}{.5em}{}
1918 \titlespacing{\section}
1919 {4pc}{1.5pc plus .1ex minus .2ex}{1pc}
1920
1921 \section*{Example of margin section}
1922
1923 Which is followed by some text to show the result.
1924 But do not stop reading, because the following example illustrates how
1925 to take advantage of other packages. The last command in the last
1926 argument can take an argument, which is the title with no
1927 additional command inside it. We just give the code, but you
1928 may try it by yourself. Thus, with the \textsf{soul} package
1929 you may say
1930 \begin{verbatim}
1931 \newcommand{\secformat}[1]{\MakeLowercase{\so{#1}}}
1932 % \so spaces out letters
1933 \titleformat{\section}[block]
1934 {\normalfont\scshape\filcenter}
1935 {\thesection}
1936 {1em}
1937 {\secformat}
1938 \end{verbatim}
1939
1940 The margin title above was defined:
1941 \begin{verbatim}
1942 \titleformat{\section}[leftmargin]
1943 {\normalfont
1944 \titlerule*[.6em]{\bfseries.}%
1945 \vspace{6pt}%
1946 \sffamily\bfseries\filleft}
1947 {\thesection}{.5em}{}
1948 \titlespacing{\section}
1949 {4pc}{1.5ex plus .1ex minus .2ex}{1pc}
1950 \end{verbatim}
1951
1952 \examplesep
1953
1954 The following examples are intended for chapters. However, this
1955 document lacks of |\chapter| and are showed using |\section|s
1956 with slight changes.
1957
1958 \titlespacing{\section}{0pt}{*4}{*4}
1959 \titleformat{\section}[display]
1960 {\normalfont\Large\filcenter\sffamily}
1961 {\titlerule[1pt]%
1962 \vspace{1pt}%
1963 \titlerule
1964 \vspace{1pc}%
1965 \LARGE\MakeUppercase{chapter} \thesection}
1966 {1pc}
1967 {\titlerule
1968 \vspace{1pc}%
1969 \Huge}
1970
1971 \section[Appendix]{The Title}
1972
1973 \begin{verbatim}
1974 \titleformat{\chapter}[display]
1975 {\normalfont\Large\filcenter\sffamily}
1976 {\titlerule[1pt]%
1977 \vspace{1pt}%
1978 \titlerule
1979 \vspace{1pc}%
1980 \LARGE\MakeUppercase{\chaptertitlename} \thechapter}
1981 {1pc}
1982 {\titlerule
1983 \vspace{1pc}%
1984 \Huge}
1985 \end{verbatim}
1986
1987 \examplesep
1988
1989 \def\thesection{\Roman{section}}
1990 \titleformat{\section}[display]
1991 {\bfseries\Large}
1992 {\filleft\MakeUppercase{chapter} \Huge\thesection}
1993 {4ex}
1994 {\titlerule
1995 \vspace{2ex}%
1996 \filright}
1997 [\vspace{2ex}%
1998 \titlerule]
1999
2000 \section[Appendix]{The Title}
2001
2002 \begin{verbatim}
2003 \renewcommand{\thechapter}{\Roman{chapter}}
2004 \titleformat{\chapter}[display]
2005 {\bfseries\Large}
2006 {\filleft\MakeUppercase{\chaptertitlename} \Huge\thechapter}
2007 {4ex}
2008 {\titlerule
2009 \vspace{2ex}%
2010 \filright}
2011 [\vspace{2ex}%
2012 \titlerule]
2013 \end{verbatim}
2014
2015 \addtocontents{toc}{\protect\setcounter{tocdepth}{2}\ignorespaces}
2016 \setcounter{section}{8}
2017 \endgroup
2018
2019 \bigskip
2020
2021 \subsection{A full example}
2022
2023 Now an example of a complete title scheme follows.
2024
2025 \begin{verbatim}
2026 \documentclass[twoside]{report}
2027 \usepackage[sf,sl,outermarks]{titlesec}
2028
2029 % \chapter, \subsection...: no additional code
2030
2031 \titleformat{\section}
2032 {\LARGE\sffamily\slshape}
2033 {\thesection}{1em}{}
2034 \titlespacing{\section}
2035 {-6pc}{3.5ex plus .1ex minus .2ex}{1.5ex minus .1ex}
2036
2037 \titleformat{\paragraph}[leftmargin]
2038 {\sffamily\slshape\filright}
2039 {}{}{}
2040 \titlespacing{\paragraph}
2041 {5pc}{1.5ex minus .1 ex}{1pc}
2042
2043 % 5+1=6, ie, the negative left margin in section
2044
2045 \widenhead{6pc}{0pc}
2046
2047 \renewpagestyle{plain}{}
2048
2049 \newpagestyle{special}[\small\sffamily]{
2050 \headrule
2051 \sethead[\usepage][\textsl{\chaptertitle}][]
2052 {}{\textsl{\chaptertitle}}{\usepage}}
2053
2054 \newpagestyle{main}[\small\sffamily]{
2055 \headrule
2056 \sethead[\usepage][\textsl{\thechapter. \chaptertitle}][]
2057 {}{\textsl{\thesection. \sectiontitle}}{\usepage}}
2058
2059 \pagestyle{special}
2060
2061 \begin{document}
2062
2063 ---TOC
2064
2065 \pagestyle{main}
2066
2067 ---Body
2068
2069 \pagestyle{special}
2070
2071 ---Index
2072 \end{document}
2073 \end{verbatim}
2074
2075 \subsection{Standard Classes}
2076
2077 Now follows, for your records, how sectioning commands of standard
2078 classes could be defined.
2079 \begin{verbatim}
2080 \titleformat{\chapter}[display]
2081 {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
2082 \titleformat{\section}
2083 {\normalfont\Large\bfseries}{\thesection}{1em}{}
2084 \titleformat{\subsection}
2085 {\normalfont\large\bfseries}{\thesubsection}{1em}{}
2086 \titleformat{\subsubsection}
2087 {\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}
2088 \titleformat{\paragraph}[runin]
2089 {\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
2090 \titleformat{\subparagraph}[runin]
2091 {\normalfont\normalsize\bfseries}{\thesubparagraph}{1em}{}
2092
2093 \titlespacing*{\chapter} {0pt}{50pt}{40pt}
2094 \titlespacing*{\section} {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
2095 \titlespacing*{\subsection} {0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
2096 \titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
2097 \titlespacing*{\paragraph} {0pt}{3.25ex plus 1ex minus .2ex}{1em}
2098 \titlespacing*{\subparagraph} {\parindent}{3.25ex plus 1ex minus .2ex}{1em}
2099 \end{verbatim}
2100
2101 \subsection{Chapter Example}
2102
2103 A final example shows how to take advantage of the |picture|
2104 environment for fancy sectioning formats. Even with the simple
2105 tools provided by standard \LaTeX{} you may create impressive
2106 titles but you may devise more elaborated
2107 ones with, for instance, |pspicture| (\textsf{PSTricks}
2108 package) or by including graphics created with the help of external
2109 programs.
2110
2111 \begin{verbatim}
2112 \usepackage[dvips]{color}
2113 \usepackage[rigidchapters,explicit]{titlesec}
2114
2115 \DeclareFixedFont{\chapterfont}{T1}{phv}{bx}{n}{11cm}
2116
2117 \titlespacing{\chapter}{0pt}{0pt}{210pt}
2118 % Most of titles have some depth. The total space is
2119 % a bit larger than the picture box.
2120
2121 \titleformat{\chapter}[block]
2122 {\begin{picture}(330,200)}
2123 {\put(450,80){%
2124 \makebox(0,0)[rb]{%
2125 \chapterfont\textcolor[named]{SkyBlue}{\thechapter}}}
2126 \put(0,230){%
2127 \makebox(0,0)[lb]{%
2128 \Huge\sffamily\underline{Chapter \thechapter}}}}
2129 {0pt}
2130 {\put(0,190){\parbox[t]{300pt}{%
2131 \Huge\sffamily\filright#1}}}
2132 [\end{picture}]
2133 \end{verbatim}
2134
2135 (The exact values to be used depend on the text area,
2136 class, |\unitlength|, paper size, etc.)
2137
2138 \end{document}
2139
2140 MIT License
2141 -----------
2142
2143 Permission is hereby granted, free of charge, to any person obtaining a
2144 copy of this software and associated documentation files (the
2145 "Software"), to deal in the Software without restriction, including
2146 without limitation the rights to use, copy, modify, merge, publish,
2147 distribute, sublicense, and/or sell copies of the Software, and to
2148 permit persons to whom the Software is furnished to do so, subject to
2149 the following conditions:
2150
2151 The above copyright notice and this permission notice shall be included
2152 in all copies or substantial portions of the Software.
2153
2154 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2155 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2156 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2157 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
2158 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2159 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2160 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.