Add a line break to section title at compile

My section titles have this pattern:

Chapter 1 - FooBar

In the PDF I need to have the word “Chapter 1” in one line and “FooBar” in the second line. The text needs to be horizontal centered + the word “FooBar” has to be bold and italic.

My first idea was to not print the section title and instead add the ready formatted text to a page and compile “as-is”. Unfortunately Scrivener does not add a PDF outline for the chapter than.

How do I get a PDF outline with the content “Chapter 1 - FooBar” and have the text formatted as described above?

Wouldn’t one of the alternate Section Layouts that displays a two-line chapter heading work for you? There is one in fact that work just like you’re asking for, where the item the layout is used for takes the binder name for the second heading line. It depends on the Format you’re starting from of course. The “Default” one is very simple and meant more to be a starting point. I’d take a look at how something like the Paperback format can produce headings, for ideas in your own project.

[size=80]An example from the Paperback format, out of the box.[/size]

The selected Layout is assigned to the “Heading” section type, which is being used by the two highlighted folders on the right. “Section title” here stands in for “Red Book” and “Black Book” as they will be printed into the layout.

Will the entry in the PDF outline in your example “Chapter One Red Book” or just “Red Book” ?

It would be either/or, without some further fiddling. You can have the prefix by itself or the title by itself, with the latter overriding the former if it exists. Given that, you could get the whole thing printed in the sidebar, using a prefix only, and specifying the title of the document in the prefix using the placeholder tag, instead of the checkbox in the Layout list. Here for example is a modified “Chapter with Title” prefix:

Chapter <$t:chapter><$rst_scene> *<$title>*

The downside is limited per-line formatting since all of this information is coming from the same field. We dodge around part of that problem by making use of a simple and direct approach, with the project compile setting (back in overview, under the General Options tab): Convert Markdown to rich text in titles and synopses. The asterisks in our example will italicise the title.

By the way, depending on which Format you start from, you may need to go into the PDF Settings compile format pane and switch off the print stuff at the top, and make sure Generate PDF outline is enabled.

If the title can be inserted by the <$title> placeholder a possibility might be to allow regex in the prefix and suffix. With this I could replace the dash (-) with a line break and would be able to format parts of the title.