### 3.2.2 Custom titles headers and footers

#### Custom text formatting for titles

Standard `\markup` commands can be used to customize any header, footer and title text within the `\header` block.

>     \score {
>       { s1 }
>       \header {
>         piece = \markup { \fontsize #4 \bold "PRAELUDIUM I" }
>         opus = \markup { \italic "BWV 846" }
>       }
>     }

#### See also

Notation Reference: Formatting text.

#### Custom layout for titles

`\markup` commands in the `\header` block are useful for simple text formatting, but they do not allow precise control over the placement of titles. To customize the placement of the text fields, change either or both of the following `\paper` variables:

- `bookTitleMarkup`
- `scoreTitleMarkup`

The placement of titles when using the default values of these `\markup` variables is shown in the examples in Default layout of bookpart and score titles.

The default settings for `scoreTitleMarkup` as defined in ‘`ly/titling-init.ly`’ are:

>     scoreTitleMarkup = \markup { \column {
>       \on-the-fly \print-all-headers { \bookTitleMarkup \hspace #1 }
>       \fill-line {
>         \fromproperty #'header:piece
>         \fromproperty #'header:opus
>       }
>     }
>     }

This places the `piece` and `opus` text fields at opposite ends of the same line:

>     \score {
>       { s1 }
>       \header {
>         piece = "PRAELUDIUM I"
>         opus = "BWV 846"
>       }
>     }

This example redefines `scoreTitleMarkup` so that the `piece` text field is centered and in a large, bold font.

>     \book {
>       \paper {
>         indent = 0\mm
>         scoreTitleMarkup = \markup {
>           \fill-line {
>             \null
>             \fontsize #4 \bold \fromproperty #'header:piece
>             \fromproperty #'header:opus
>           }
>         }
>       }
>       \header { tagline = ##f }
>       \score {
>         { s1 }
>         \header {
>           piece = "PRAELUDIUM I"
>           opus = "BWV 846"
>         }
>       }
>     }

Text fields not normally effective in score `\header` blocks can be printed in the Score Title area if `print-all-headers` is placed inside the `\paper` block. A disadvantage of using this method is that text fields that are intended specifically for the Bookpart Title area need to be manually suppressed in every `\score` block. See Titles explained.

To avoid this, add the desired text field to the `scoreTitleMarkup` definition. In the following example, the `composer` text field (normally associated with `bookTitleMarkup`) is added to `scoreTitleMarkup`, allowing each score to list a different composer:

>     \book {
>       \paper {
>         indent = 0\mm
>         scoreTitleMarkup = \markup {
>           \fill-line {
>             \null
>             \fontsize #4 \bold \fromproperty #'header:piece
>             \fromproperty #'header:composer
>           }
>         }
>       }
>       \header { tagline = ##f }
>       \score {
>         { s1 }
>         \header {
>           piece = "MENUET"
>           composer = "Christian Petzold"
>         }
>       }
>       \score {
>         { s1 }
>         \header {
>           piece = "RONDEAU"
>           composer = "François Couperin"
>         }
>       }
>     }

It is also possible to create your own custom text fields, and refer to them in the markup definition.

>     \book {
>       \paper {
>         indent = 0\mm
>         scoreTitleMarkup = \markup {
>           \fill-line {
>             \null
>             \override #`(direction . ,UP) {
>               \dir-column {
>                 \center-align \fontsize #-1 \bold
>                   \fromproperty #'header:mycustomtext %% User-defined field
>                 \center-align \fontsize #4 \bold
>                   \fromproperty #'header:piece
>               }
>             }
>             \fromproperty #'header:opus
>           }
>         }
>       }
>       \header { tagline = ##f }
>       \score {
>         { s1 }
>         \header {
>           piece = "FUGA I"
>           mycustomtext = "A 4 VOCI" %% User-defined field
>           opus = "BWV 846"
>         }
>       }
>     }

#### See also

Notation Reference: Titles explained.

#### Custom layout for headers and footers

`\markup` commands in the `\header` block are useful for simple text formatting, but they do not allow precise control over the placement of headers and footers. To customize the placement of the text fields, use either or both of the following `\paper` variables:

- `oddHeaderMarkup`
- `evenHeaderMarkup`
- `oddFooterMarkup`
- `evenFooterMarkup`

The `\markup` command `\on-the-fly` can be used to add markup conditionally to header and footer text defined within the `\paper` block, using the following syntax:

>     variable = \markup {
>       …
>       \on-the-fly  \procedure  markup
>       …
>     }

The procedure is called each time the `\markup` command in which it appears is evaluated. The procedure should test for a particular condition and interpret (i.e. print) the markup argument if and only if the condition is true.

A number of ready-made procedures for testing various conditions are provided:

> Procedure name | Condition tested
> --- | ---
> print-page-number-check-first | should this page number be printed?
> create-page-number-stencil | print-page-numbers true?
> print-all-headers | print-all-headers true?
> first-page | first page in the book?
> (on-page nmbr) | page number = nmbr?
> last-page | last page in the book?
> not-first-page | not first page in the book?
> part-first-page | first page in the book part?
> part-last-page | last page in the book part?
> not-single-page | pages in book part > 1?

The following example centers page numbers at the bottom of every page. First, the default settings for `oddHeaderMarkup` and `evenHeaderMarkup` are removed by defining each as a null markup. Then, `oddFooterMarkup` is redefined with the page number centered. Finally, `evenFooterMarkup` is given the same layout by defining it as `\oddFooterMarkup`:

>     \book {
>       \paper {
>         print-page-number = ##t
>         print-first-page-number = ##t
>         oddHeaderMarkup = \markup \null
>         evenHeaderMarkup = \markup \null
>         oddFooterMarkup = \markup {
>           \fill-line {
>             \on-the-fly \print-page-number-check-first
>             \fromproperty #'page:page-number-string
>           }
>         }
>         evenFooterMarkup = \oddFooterMarkup
>       }
>       \score {
>         \new Staff { s1 \break s1 \break s1 }
>       }
>     }

Several `\on-the-fly` conditions can be combined with an ‘and’ operation, for example,

>       \on-the-fly \first-page
>       \on-the-fly \last-page
>       { \markup … \fromproperty #'header: … }

determines if the output is a single page.

#### See also

Notation Reference: Titles explained, Default layout of bookpart and score titles.

Installed Files: ‘`../ly/titling-init.ly`’.

其他语言：español, français, italiano。
About automatic language selection.

#### LilyPond — Notation Reference v2.18.2 (稳定分支).