| 1 |
<?xml version="1.0" encoding="iso-8859-1"?> |
| 2 |
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"> |
| 4 |
<section id="sec-section-num"> |
| 5 |
<title>Chapter and Section numbering</title> |
| 6 |
|
| 7 |
<section> |
| 8 |
<title>Depth of Section numbering and Table Of Content</title> |
| 9 |
|
| 10 |
<para><command>Dblatex</command> relies on latex to automatically compute the |
| 11 |
chapter and section numbers. It also relies on latex to produce the headings |
| 12 |
with these numbers, and to produce the Table Of Content containing these |
| 13 |
entries.</para> |
| 14 |
|
| 15 |
<para>Some specific sections like <sgmltag>preface</sgmltag>, |
| 16 |
<sgmltag>colophon</sgmltag>, or <sgmltag>dedication</sgmltag> are not numbered |
| 17 |
because they are displayed in front and back matters, but they can be listed in |
| 18 |
the TOC if the related parameters are set |
| 19 |
(<parameter>dedication.tocdepth</parameter>, <parameter>preface.tocdepth</parameter>, <parameter>colophon.tocdepth</parameter>).</para> |
| 20 |
|
| 21 |
<para>More generally you can configure the depth of the chapter and section |
| 22 |
numbering with the parameter <parameter>doc.section.depth</parameter>, and the |
| 23 |
depth of the entries in the TOC with the parameter |
| 24 |
<parameter>toc.section.depth</parameter></para>. |
| 25 |
|
| 26 |
<para>Note however that an unumbered section |
| 27 |
becomes an informal component, and therefore you can only link to such a section |
| 28 |
by using a specific xrefstyle because their label built with the |
| 29 |
automatic number does not exist anymore. The other drawback is that |
| 30 |
all the sections included in an unnumbered section or chapter are |
| 31 |
unnumbered.</para> |
| 32 |
|
| 33 |
</section> |
| 34 |
<section> |
| 35 |
<title>Using the latex style for section numbering</title> |
| 36 |
|
| 37 |
<para>A well customized latex style can be a powerfull yet versatile |
| 38 |
alternative to the use of section and/or TOC depth parameter. With some latex |
| 39 |
packages you can easily format the headings to remove the numbers, or transform them. See <xref linkend="sec-custom-latex"/> to know how to use your own latex |
| 40 |
style with <command>dblatex</command>.</para> |
| 41 |
|
| 42 |
<para>The benefit of this method is that you can fully control how the titles |
| 43 |
must be displayed, you do not have to play with latex counters to have the right |
| 44 |
depth, and the sections do not lost their formal number label.</para> |
| 45 |
|
| 46 |
<para>The following example shows how you can customize the chapter title by |
| 47 |
using the latex package titlesec, and shows how to remove the chapter label in |
| 48 |
the Table Of Content with the package titletoc. Look in particular in the |
| 49 |
listing where text is emphasized.</para> |
| 50 |
|
| 51 |
<para><programlisting language="tex"> |
| 52 |
<![CDATA[\usepackage{titlesec} |
| 53 |
|
| 54 |
%% Example 1: Redefines the heading to remove the chapter label |
| 55 |
%% The 2nd parameter only contains \filcenter without any label |
| 56 |
\titleformat{\chapter}[block] |
| 57 |
{\filcenter\huge}{]]><emphasis role="bold"><![CDATA[\filcenter]]></emphasis><![CDATA[}{20pt}{\Huge} |
| 58 |
|
| 59 |
%% Example 2: Put the chapter number in word |
| 60 |
%% The title of the first chapter is then displayed like this: |
| 61 |
%% "Chapter One <chapter title>" |
| 62 |
\newcommand\makeletterof[1]{% |
| 63 |
\ifthenelse{\equal{#1}{1}}{ONE}{% |
| 64 |
\ifthenelse{\equal{#1}{2}}{TWO}{% |
| 65 |
\ifthenelse{\equal{#1}{3}}{THREE}{% |
| 66 |
\ifthenelse{\equal{#1}{4}}{FOUR}{% |
| 67 |
\ifthenelse{\equal{#1}{5}}{FIVE}{% |
| 68 |
\ifthenelse{\equal{#1}{6}}{SIX}{% |
| 69 |
\ifthenelse{\equal{#1}{7}}{SEVEN}{% |
| 70 |
\ifthenelse{\equal{#1}{8}}{EIGHT}{% |
| 71 |
\ifthenelse{\equal{#1}{9}}{NINE}{% |
| 72 |
\ifthenelse{\equal{#1}{10}}{TEN}{% |
| 73 |
\ifthenelse{\equal{#1}{11}}{ELEVEN}{% |
| 74 |
\ifthenelse{\equal{#1}{12}}{TWELVE}{% |
| 75 |
#1}}}}}}}}}}}}} |
| 76 |
|
| 77 |
\titleformat{\chapter}[block] |
| 78 |
{\filcenter\ttfamily\huge}% |
| 79 |
{]]><emphasis role="bold"><![CDATA[\filcenter\MakeUppercase{\chaptertitlename} \makeletterof{\thechapter}]]></emphasis><![CDATA[}{20pt}{\Huge} |
| 80 |
|
| 81 |
|
| 82 |
%% Make TOC entries for chapters without label |
| 83 |
\usepackage{titletoc} |
| 84 |
|
| 85 |
\titlecontents{chapter} % |
| 86 |
[1.5em] % |
| 87 |
{\addvspace{1em plus 0pt}\bfseries} % |
| 88 |
{]]><emphasis role="bold"><![CDATA[\hspace{-1.3em}]]></emphasis><![CDATA[} % no number, remove room reserved for it |
| 89 |
{\hspace{-1.3em}} % |
| 90 |
{\hfill \contentspage} % |
| 91 |
[\addvspace {0pt}] |
| 92 |
]]></programlisting></para> |
| 93 |
|
| 94 |
</section> |
| 95 |
<section> |
| 96 |
<title>Using the <sgmltag>label</sgmltag> attribute</title> |
| 97 |
|
| 98 |
<para>If you need to mix numbered and not numbered chapters, the numbering depth |
| 99 |
parameters will not help. The latex style will not easily detect that for |
| 100 |
some chapters the number should be displayed and for others it should not. |
| 101 |
</para> |
| 102 |
|
| 103 |
<para>To mix numbered and unnumbered chapters you can use a label with an |
| 104 |
empty string for the chapters that must not be numbered, as shown by the example |
| 105 |
below.</para> |
| 106 |
|
| 107 |
<para><programlisting language="XML"> |
| 108 |
<![CDATA[<chapter id="intro" ]]><emphasis role="bold">label=""</emphasis><![CDATA[><title>Introduction</title> |
| 109 |
<!-- This chapter must be displayed with no number, like a preface --> |
| 110 |
</chapter> |
| 111 |
<chapter id="before" ]]><emphasis role="bold">label=""</emphasis><![CDATA[><title>Pre-requisite</title> |
| 112 |
<!-- This chapter must be displayed with no number, like a preface --> |
| 113 |
</chapter> |
| 114 |
<chapter id="chap1"><title>First chapter</title> |
| 115 |
<!-- First numbered chapter --> |
| 116 |
</chapter> |
| 117 |
... |
| 118 |
<chapter id="after" ]]><emphasis role="bold">label=""</emphasis><![CDATA[><title>Conclusion</title> |
| 119 |
<!-- This chapter must be displayed with no number, like a colophon --> |
| 120 |
</chapter> |
| 121 |
... |
| 122 |
]]></programlisting></para> |
| 123 |
|
| 124 |
<para>You can also set a label to a specific integer to force a section |
| 125 |
counter. In this case there is no more automatic numbering. The automatic |
| 126 |
numbering then applies to the following sections that increment the counter |
| 127 |
set for this section if there is no label.</para> |
| 128 |
|
| 129 |
<para><programlisting language="XML"> |
| 130 |
<![CDATA[<chapter id="intro" ]]><emphasis role="bold">label="2"</emphasis><![CDATA[><title>Introduction</title> |
| 131 |
<!-- This chapter is forced to have number 2 (it should be 1) --> |
| 132 |
<section id="s1" ]]><emphasis |
| 133 |
role="bold">label="3"</emphasis><![CDATA[><title>Section 2.3</title> |
| 134 |
<!-- This section is forced to have number 3 (it should be 1) --> |
| 135 |
<section id="s11" ]]><emphasis |
| 136 |
role="bold">label="4"</emphasis><![CDATA[><title>Section 2.3.4</title> |
| 137 |
<!-- This section is forced to have number 4 (it should be 1) --> |
| 138 |
</section> |
| 139 |
</section> |
| 140 |
</chapter> |
| 141 |
]]></programlisting></para> |
| 142 |
|
| 143 |
</section> |
| 144 |
|
| 145 |
</section> |