Automatic hierarchical section title numbering in compile

Hello, I have two questions.

  1. Is there a way to make an automatic hierarchical section title numbering in SC3?
    For example, I have a file as below:

Then I want to automatically put numberings as follows when compiling:

  1. Introduction
  2. Background and Context
    2-1. Architectural Representation
    2-2. Generative Design machines
    2-2-1. Other case
  3. Problem Statement

Using a placeholder tags in front of the individual document title, such as “<$n:chapter><$rst_subchapter> Document Title”, may allow this, but then I have to put this to every title manually in my file, and it will make the doc look confusing and inflexible to move it around.

  1. Is it possible to specify difference compilation settings of the document according to its depth in the document hierarchy? For instance, from the example above, is it possible to assign different page brake settings and the title text formats to “2. Background and Context” and “2-1. Architectural Representation” and so on?

I’ll offer a brief reply with the caveat that I’m a novice. You seem to want to proceed from the structure of your project (i.e. the nesting of the folders and so on) to a numbering scheme for headings and to layout. This is possible.

Type tags act as intermediaries between structure and layout. Types are associated with structure in
Project > Project Settings
You can construct a type for each layer in the hierarchy that you are interested in.

Layouts are made by editing a compile format. It’s possible to control fonts, indentations and title numbering (and much more) in layouts. You might construct several layouts, for example, you might have a layout that formats a level two heading, and another that formats a level three heading and so on.

You can create a hierarchical numbering scheme in a layout by editing the Title Options for the layout and adding a title prefix <$hn>. This yields hierarchical numbering scheme like 2.1.3. This isn’t exactly what you wanted (you wanted 2-1-3) but it’s close.

Types are connected to layouts in the middle panel of the compile window, using the button “Assign Section Layouts”.

In summary, you connect structure to types, and types to layouts to achieve what you want. I hope this is helpful.

John

JohnF has given you a good answer here, which should set you on your way. Just to add:

As JohnF says, you can use <$hn>, which will use periods instead of dashes but otherwise does as you want.

You do not have to put placeholders directly in titles - in fact I would strongly recommend against it for exactly the reasons you give (it would look unwieldy and render binder titles difficult to read). This is exactly what title prefixes are for in Compile. In Compile, you would create a “Section Layout” and add a the placeholders as title prefixes. This way, they do not appear in the binder, but only get added to the compiled documents.

It’s not only possible, but it is, in fact, one of the core features of Scrivener. I recommend going through the interactive tutorial, especial the parts on Compile. In particular - as, again, JohnF has pointed out:

  1. For documents you want compiled differently, you assign a different “Section Type”. Section Types are set up in Project > Project Settings.

  2. You can set up Section Types to be assigned automatically according to the binder hierarchy using the “Default Types by Structure” feature under “Section Types” in Project > Project Settings.

  3. In Compile, you create different “Section Layouts”. A Section Layout tells Scrivener how to format a particular document. You then use “Assign Section Layouts…” in Compile to assign the Section Layouts of a Compile Format to the Section Types of documents in a project.

For instance, suppose you create Section Types in your project named “Part”, “Section” and “Sub-Section”. In Compile, you might then choose to assign these to the Section Layouts “Heading 1 with Text”, “Heading 2 with Text” and “Heading 3 with Text” (if such layouts were available in the Compile Format you are using).

You do need to familiarise yourself with Compile to achieve all of this. These core concepts may seem a little alien at first, but once you grasp them, you will find that you can set up Compile to do a wide range of things.

For instance, suppose a hierarchical format using periods (1.2, 3.2.4 and so on) is not acceptable for what you are doing, making the <$hn> placeholder useless to you. You could instead build your own hierarchical tags as follows:

Level 1 documents = <$n:lev1>. TITLE<$rst_lev2><$rst_lev3>
Level 2 documents = <$n#lev1>-<$n:lev2>. TITLE<$rst_lev2>
Level 3 documents = <$n#lev1>-<$n#lev2>-<$n:lev3> TITLE

This tells the compiler:

  1. For level 1 documents add an Arabic number before the title (tagged “lev1” to differentiate it from other numbers) and reset any numbers tagged “lev2” or “lev3”.

  2. For level 2 documents, prefix the title with the current “lev1” number (<$n#lev1> will be replaced with whatever the last value of <$n:lev1> was), a hyphen, and then add a new number tagged “lev2”. Then reset any numbers tagged “lev3”.

  3. The same is then done for level 3 documents.

This will result in exactly what you want - hierarchical numbers using hyphens.

I have attached a sample project showing how this could be done. Be sure to look at:

  1. Project Settings > Section Types (check both panes, including “Default Type by Section”). Note that I have just created Section Types named “Level 1”, “Level 2” etc - these could be named anything you want.

  2. Take a look at the Section Type in the Inspector for each document in the binder, noting how they are correctly labelled “Level 1”, “Level 2” etc.

  3. In Compile, take a look at “Assign Section Layouts…”. Note how the section types (“Level 1” etc) on the left are assigned to the Section Layouts on the right - that is, the previews on the right show how documents using these Section Types will look when compiled.

  4. Ctrl-click on the “Hierarchy Test” Compile Format in Compile, choose “Edit” and look at how the Section Layouts are set up. Particular look under “Title Options”. You will see that each Section Layout is set up to add the necessary number prefixes.

Please bear in mind that what we are doing here is quite advanced, so if you are new to Scrivener this might be a bit confusing at first because we are taking advantage of some of its more nitty-gritty and deep-down features to create a hierarchical numbering system that Scrivener doesn’t know about or support out of the box.

IMPORTANT NOTE: While putting together this reply, I noticed that there is a bug in the current version of Scrivener whereby the above example will not work correctly. When you compile using 3.0.2, you will notice that the hierarchical numbering in my sample project comes out wrong, with both 2.1 and 2.2 being labelled “2.1”. I have fixed this for 3.0.3, which will be out later this week or early next week, so please wait for that to test this properly.

All the best,
Keith
VariableHierarchy1.zip (90.8 KB)

This was helpful. Now, how do I get the hierarchical numbering to continue at the paragraph level? For example:

  1. Heading
    1.1 Sub-heading
    1.1.1 Some paragraph text

I’m working on a policy document, and the office requires that every heading and paragraph have sequential hierarchical numbering.

It is possible:

  1. to create a style,
  2. add a line-numbering placeholder as a prefix, such as <$hn>.<$n:para>,
  3. and assign the style to paragraphs.

Other people might have better solutions.

Sample Mac project and compiled PDF attached. Don’t know if Windows can compile in the same way.

Merx

[attachment=0]NP.zip[/attachment]

Ah, thank you very much. Sadly, it seems that what compiled on your Mac did not compile the same way on Windows. But I am grateful for your help, as I was beginning to think that the Windows version was not yet capable of what the Mac version can do. For the sake of interest, I attach the PDF of how that sample project compiled.

[attachment=0]np.pdf[/attachment]

Welcome.

But not want anyone wanted.

Probably worth asking on the Windows tech-support forum:

viewforum.php?f=30

Good luck.

Merx

Hi KB,
Thank you for the sample file you provided here. The visual example is so helpful and I am going to replicate this in my document. However, have two questions:

  1. is there any way I can import these layout settings into my existing document? I tried to replicate the VariableHierachy structure on my own, with the Level 1, Level 2, and Level 3 but it’s a mess.
  2. pardon my annoyance here, but unlike the original poster, I would like to use periods instead of dashes. If i were to use the <$hn> placeholder, there would be some Level 2 documents printed when I only need the title printed. How should I set the level Two settings so that it appears similar to Level 2 in VariableHierarchy1?
  3. Also, in the formatting tab, I have set it to 1.5 spacing, and even though I press “Save” the compiled version always spits out a 1.0 spaced document. I’m not sure why.
    Nhister

Export the format like so:

Do you mean dashes generated by the code for level 2 and 3 described above? If so, just change the dashes to dots.

Did you turn on the “override formatting” checkbox and click in the sample text to change spacing? Maybe you clicked in the title area instead.

Thank you for your response, Keith. I’ve imported the style/section layouts as you showed and it seemed to work. However, the section types (eg Level 1, 2, 3) are not available in the Compile options window.
I tried to attach a screenshot and I’m getting an error message saying that I can’t embed media items in a post.

I’m unable to change the dashes to dots in the formatting box in the “1-1 Section Title”; is this where I’m supposed to change it? Again, I can’t embed a screenshot here for some reason.

I’m not sure if you work for L&L, but would you open to doing a short Zoom session with me so I can figure this out? I’m very close to giving up on Scrivener (again).

Hmm… yep, he kinda does.

And to answer your question, yes I did turn on “override formatting”, but the compiled version is still giving me 2.0 spacing. My submission guidelines require 1.5 spacing.

AND did you click in the sample text before changing line spacing?

Keith is the founder, and he wrote virtually all of the Mac and iOS Scrivener code.

They don’t do zoom sessions, otoh.

KB, Thank you for this.

I tried to assign different font sizes for the title in each different layout (as is required by my examiners), but I couldn’t get it to work; nor the 1.5 spacing issue. It looks like it is not possible do set one font size for the title and another one for the text (same with line spacing) in the section layouts. I’ll deal with it later. So for this reason, I used the <$hn> placeholder in the Section Layouts/Title Options/Prefix and all my Titles are numbered numerically a hierarchical fashion - even if the titles are the same font size.

My next question is, now that I have all of these titles numbered nicely, is there a way to put them in one document - for my Table of Contents? The Scrivener Tutorial, Scrivener Manual seem to indicate that a TOC is only possible for epubs and Kindle books. I figured since the list of placeholders is incremented somewhere, I hopefully would be able to extract that information and put it into a TOC somehow. I will have to do something similar for the “List of Figures” and “List of Graphs”, so it would be nice to know how to do that now. If the TOC can only be done in word, please let me know if you are aware of any resources that might facilitate my understanding of the process. Thank you for any suggestions you have to share.

Yes, you can use different fonts for titles vs. text. In the Section Layout editor, make sure your cursor is in the relevant preview text.

Yes, you can create Tables of Contents for documents other than ebooks. See Section 22.1 in the (Mac) manual.

Thanks for that. I’m sorry if I wasn’t clear, following the hierarchical numbering of sections that I now have throughout my document, I would ilke the TOC to have the 1) Hierarchircal numbering+Section Title+ page.

22.1 doesn’t output the hierarchical numbering - just the document titles. Ive been using the <$hn> in the Section Layout/Title Options/Prefix, should I be numbering a different way?

Also, I need to do this for figures. All the figures (30-40 at this point) are embedded in my text documents with <$n:figure:myFigureName>. How do I generate a TOC for them?