1

I'd need to add the Chapter title in the page's heading of PDF files generated with Asciidoctor-toPDF. Here is the set of Properties I'm using at the beginning of my doc:

= Book title
:notitle:
:toc: left
:toclevels: 8 
:sectnums:
:sectnumlevels: 8
:source-highlighter: coderay 
:icons: font
:chapter-label:
:header_recto_content_center: '{section-title}'

Is there any property I am missing or which conflicts with the Header generation?

Carla
  • 3,064
  • 8
  • 36
  • 65

1 Answers1

1

A few theme-related attributes exist. But header is not one of them unfortunately.

So to style the header of a PDF one must resort to a custom style in YAML format.

Style

For this example the file is named style.yml and placed in our working directory.

extends: default   #1

header:
  height: 15mm     #2
  recto: &header   #3
    center-content: '-- {section-or-chapter-title} --' #4
  verso: *header   #5
  1. Extends the default asciidoctor-pdf theme with your customized code.
  2. Define the height of the header or the content will not show; also explained here.
  3. Create a YAML anchor to the whole content of recto.
  4. The use of {section-or-chapter-title} is explained and shown at the end of the post.
  5. Reference the content from &header. In plain make verso behave the same as recto.

Document

The content of the adoc file is as shown below. The file is aptly named book.adoc and placed in the same directory as style.yml.

= Book title
:notitle:
:toc: left
:toclevels: 8 
:sectnums:
:sectnumlevels: 8
:source-highlighter: coderay 
:icons: font
:chapter-label:

== Chapter One

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy 
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam 
voluptua.

== Chapter Two

=== Section One

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy 
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam 
voluptua.

Conversion

PDF conversion is done using the pdf-stylesdir and pdf-style attributes.

asciidoctor-pdf -a pdf-stylesdir=. -a pdf-style=style.yml -d book book.adoc

Result

Chapter one looks then as shown in the screenshot. As there is no section header the chapter is used to populate the header.

enter image description here

Chapter two having both a chapter and a section defined is displaying the section title in the header.

enter image description here

uroesch
  • 161
  • 3