Blob Blame History Raw
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Chapter and Section numbering</title><link rel="stylesheet" type="text/css" href="manual.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.76.1" /><link rel="home" href="index.html" title="DocBook to LaTeX Publishing" /><link rel="up" href="ch03.html" title="Chapter 3. Using dblatex" /><link rel="prev" href="sec-covers.html" title="Book Covers" /><link rel="next" href="sec-figinclude.html" title="Figure Inclusion" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter and Section numbering</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="sec-covers.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Using dblatex</th><td width="20%" align="right"> <a accesskey="n" href="sec-figinclude.html">Next</a></td></tr></table><hr /></div><div class="section" title="Chapter and Section numbering"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="sec-section-num"></a>Chapter and Section numbering</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="sec-section-num.html#idp3977312">Depth of Section numbering and Table Of Content</a></span></dt><dt><span class="section"><a href="sec-section-num.html#idp1544896">Using the latex style for section numbering</a></span></dt><dt><span class="section"><a href="sec-section-num.html#idp4476232">Using the <code class="sgmltag-element">label</code> attribute</a></span></dt></dl></div><div class="section" title="Depth of Section numbering and Table Of Content"><div class="titlepage"><div><div><h3 class="title"><a id="idp3977312"></a>Depth of Section numbering and Table Of Content</h3></div></div></div><p><span class="command"><strong>Dblatex</strong></span> relies on latex to automatically compute the
chapter and section numbers. It also relies on latex to produce the headings
with these numbers, and to produce the Table Of Content containing these
entries.</p><p>Some specific sections like <code class="sgmltag-element">preface</code>,
<code class="sgmltag-element">colophon</code>, or <code class="sgmltag-element">dedication</code> are not numbered
because they are displayed in front and back matters, but they can be listed in
the TOC if the related parameters are set
(<em class="parameter"><code>dedication.tocdepth</code></em>, <em class="parameter"><code>preface.tocdepth</code></em>, <em class="parameter"><code>colophon.tocdepth</code></em>).</p><p>More generally you can configure the depth of the chapter and section
numbering with the parameter <em class="parameter"><code>doc.section.depth</code></em>, and the
depth of the entries in the TOC with the parameter
<em class="parameter"><code>toc.section.depth</code></em></p>.

<p>Note however that an unumbered section
becomes an informal component, and therefore you can only link to such a section
by using a specific xrefstyle because their label built with the
automatic number does not exist anymore. The other drawback is that
all the sections included in an unnumbered section or chapter are
unnumbered.</p></div><div class="section" title="Using the latex style for section numbering"><div class="titlepage"><div><div><h3 class="title"><a id="idp1544896"></a>Using the latex style for section numbering</h3></div></div></div><p>A well customized latex style can be a powerfull yet versatile 
alternative to the use of section and/or TOC depth parameter. With some latex
packages you can easily format the headings to remove the numbers, or transform them. See <a class="xref" href="sec-custom-latex.html" title="Customized LaTeX style">the section called “Customized LaTeX style”</a> to know how to use your own latex
style with <span class="command"><strong>dblatex</strong></span>.</p><p>The benefit of this method is that you can fully control how the titles
must be displayed, you do not have to play with latex counters to have the right
depth, and the sections do not lost their formal number label.</p><p>The following example shows how you can customize the chapter title by
using the latex package titlesec, and shows how to remove the chapter label in
the Table Of Content with the package titletoc. Look in particular in the
listing where text is emphasized.</p><pre class="programlisting">
\usepackage{titlesec}

%% Example 1: Redefines the heading to remove the chapter label
%% The 2nd parameter only contains \filcenter without any label
\titleformat{\chapter}[block]
{\filcenter\huge}{<span class="bold"><strong>\filcenter</strong></span>}{20pt}{\Huge}

%% Example 2: Put the chapter number in word
%% The title of the first chapter is then displayed like this:
%% "Chapter One &lt;chapter title&gt;"
\newcommand\makeletterof[1]{%
\ifthenelse{\equal{#1}{1}}{ONE}{%
\ifthenelse{\equal{#1}{2}}{TWO}{%
\ifthenelse{\equal{#1}{3}}{THREE}{%
\ifthenelse{\equal{#1}{4}}{FOUR}{%
\ifthenelse{\equal{#1}{5}}{FIVE}{%
\ifthenelse{\equal{#1}{6}}{SIX}{%
\ifthenelse{\equal{#1}{7}}{SEVEN}{%
\ifthenelse{\equal{#1}{8}}{EIGHT}{%
\ifthenelse{\equal{#1}{9}}{NINE}{%
\ifthenelse{\equal{#1}{10}}{TEN}{%
\ifthenelse{\equal{#1}{11}}{ELEVEN}{%
\ifthenelse{\equal{#1}{12}}{TWELVE}{%
#1}}}}}}}}}}}}}

\titleformat{\chapter}[block]
{\filcenter\ttfamily\huge}%
{<span class="bold"><strong>\filcenter\MakeUppercase{\chaptertitlename} \makeletterof{\thechapter}</strong></span>}{20pt}{\Huge}


%% Make TOC entries for chapters without label
\usepackage{titletoc}

\titlecontents{chapter} %
[1.5em] % 
{\addvspace{1em plus 0pt}\bfseries} %
{<span class="bold"><strong>\hspace{-1.3em}</strong></span>} % no number, remove room reserved for it 
{\hspace{-1.3em}} %
{\hfill \contentspage} %
[\addvspace {0pt}]
</pre></div><div class="section" title="Using the label attribute"><div class="titlepage"><div><div><h3 class="title"><a id="idp4476232"></a>Using the <code class="sgmltag-element">label</code> attribute</h3></div></div></div><p>If you need to mix numbered and not numbered chapters, the numbering depth
parameters will not help. The latex style will not easily detect that for
some chapters the number should be displayed and for others it should not.
</p><p>To mix numbered and unnumbered chapters you can use a label with an 
empty string for the chapters that must not be numbered, as shown by the example
below.</p><pre class="programlisting">
&lt;chapter id="intro" <span class="bold"><strong>label=""</strong></span>&gt;&lt;title&gt;Introduction&lt;/title&gt;
  &lt;!-- This chapter must be displayed with no number, like a preface --&gt;
&lt;/chapter&gt;
&lt;chapter id="before" <span class="bold"><strong>label=""</strong></span>&gt;&lt;title&gt;Pre-requisite&lt;/title&gt;
  &lt;!-- This chapter must be displayed with no number, like a preface --&gt;
&lt;/chapter&gt;
&lt;chapter id="chap1"&gt;&lt;title&gt;First chapter&lt;/title&gt;
  &lt;!-- First numbered chapter --&gt;
&lt;/chapter&gt;
...
&lt;chapter id="after" <span class="bold"><strong>label=""</strong></span>&gt;&lt;title&gt;Conclusion&lt;/title&gt;
  &lt;!-- This chapter must be displayed with no number, like a colophon --&gt;
&lt;/chapter&gt;
...
</pre><p>You can also set a label to a specific integer to force a section
counter. In this case there is no more automatic numbering. The automatic
numbering then applies to the following sections that increment the counter
set for this section if there is no label.</p><pre class="programlisting">
&lt;chapter id="intro" <span class="bold"><strong>label="2"</strong></span>&gt;&lt;title&gt;Introduction&lt;/title&gt;
  &lt;!-- This chapter is forced to have number 2 (it should be 1) --&gt;
  &lt;section id="s1" <span class="bold"><strong>label="3"</strong></span>&gt;&lt;title&gt;Section 2.3&lt;/title&gt;
    &lt;!-- This section is forced to have number 3 (it should be 1) --&gt;
    &lt;section id="s11" <span class="bold"><strong>label="4"</strong></span>&gt;&lt;title&gt;Section 2.3.4&lt;/title&gt;
      &lt;!-- This section is forced to have number 4 (it should be 1) --&gt;
    &lt;/section&gt;
  &lt;/section&gt;
&lt;/chapter&gt;
</pre></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sec-covers.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sec-figinclude.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Book Covers </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 
   Figure Inclusion
  </td></tr></table></div></body></html>