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
- Extends the default
asciidoctor-pdf
theme with your customized code.
- Define the height of the header or the content will not show; also explained here.
- Create a YAML anchor to the whole content of
recto
.
- The use of
{section-or-chapter-title}
is explained and shown at the end of the post.
- 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.

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