1

Wondering if you can help me with an indesign layout problem.

Any idea how I can get paragraph numbers aligned away from the spine on a facing page spread?

I've tried tinkering with the right-left direction numbering—but I am not sure how to practically target only the odd page with this, while keeping the left-right numbering on the even page.

Help appreciated! enter image description here

4
  • How is your text set up? If you’re using numbered lists, I don’t think you can – the number always comes before the text in a numbers list. If the numbers are in anchored frames, that’s much easier (you can use the Custom positioning relative to the outer margin, for example, and align the actual text away from spine). Jan 10, 2021 at 15:54
  • I've got justified left text. I am not partial to lists either way; I effectively want a chapter number placed adjacent the paragraph change in the margin facing away from the spine. So instead of having a chapter heading, I just want a number placed to the side of the text in the margin Jan 10, 2021 at 17:20
  • I’d just use anchored frames, then. Make an object style you can apply to these frames which control their position relative to the spine, and use a paragraph style with the text aligned away from spine as well. You can even use a script to automatically insert the anchored frames all in one go. Jan 10, 2021 at 17:22
  • Thanks for the tip, which script? Jan 10, 2021 at 17:43

1 Answer 1

5
+250

The easiest way to do this is, I think, by setting up some paragraph and object styles to automate the layout as much as possible, and then use a script to add in the numbers in anchored frames attached to each paragraph.

Setting up your paragraph styles

In my example here, I’ve set up a document with facing pages and some basic paragraph styles – I’ve just used [Basic Paragraph] and made a style based on it to use for those paragraphs that should be numbered (in case you need both numbered and unnumbered paragraphs). Both are left-justified and essentially identical, except that the style for the numbered paragraph is bulleted (and has no first-line indent), using the paragraph marker as the bullet (if you already have an actual paragraph marker as plain text in all the paragraphs you want numbered, you can just skip this). I’ve added a character style for the paragraph marker as well, just for show:

Numbering section of numbered paragraph style

Filling a spread with placeholder text, that gives me this:

Spread without numbering

Next, I set up a paragraph style to be used for the actual numbers – the main thing here is whether to align the numbers towards or away from the spine. I’ve chosen to align them away from the spine, so that numbers of uneven length (i.e., ‘5’ vs ‘192’) will always appear at the same distance from the text block (Edit: This is wrong – the text should be aligned towards the spine, not away from it, to achieve the desired result, so ignore that bit of the screenshot):

Paragraph numbers aligned away from spine

Setting up your object style

Finally, I set up an object style for the frames that will hold the actual numbers. The only things you really need to set up here are the paragraph style (the one just made in the previous point) and the anchored positioning options which control the frame’s positioning on the page, relative to the paragraph it’s anchored in; they should look something like this:

Object style for frames containing paragraph numbers

Note the checkmark in “Relative to spine” and that the reference point of the object (the anchored frame) is towards the spine, while the reference point for the positioning (the page margin) is away from the spine – in other words, I’m telling it to use the point on the anchored frame closest to the spine and position that point relative to the page margin furthest from the spine, at a distance of 6 mm. Or in simpler terms, ‘place the frame so it’s 6 mm from the outer edge of the text block’.

You may also want to specify some Size and Position Options to make sure that the frame inserted is big enough to contain the number (I just used “Adjust: Height and Width” and gave it a width of 12 mm and a height of 7 mm).

Adding and executing the script

Once you’ve got this all set up, go through your entire document and make sure that all the paragraphs that should be numbered have the correct style applied.

When you’ve done this, you can use a script to insert an anchored text frame at the beginning of each of these paragraphs, containing the paragraph number. It just so happens that I needed to do a similar thing not too long ago and wrote a script that does more or less that for that, so I could just adapt that script for your use case here (see below).

Add the script to your scripts panel and double-click it to run it. That should leave you with something like what you’re looking for; in my example, this:

Final result

If your paragraphs (and their numbers) change after you’ve run the script, just run it again – it will first remove all the frames with the Paragraph Numbers object style applied and then add in new ones to replace them.

 


 

The script

Copy the entire script below into a text editor (not a word processor like Word, which will likely mess it up – I’d recommend Visual Studio Code, but any code or plain-text editor will do). Change the three style names at the top to match the names you’ve used in your document. The fourth line is the text that will show up in your Undo menu (“Undo Add paragraph numbers in margin” it will say); you can change that too if you want, to anything you like.

var numberedParagraphStyle = "Numbered paragraphs";
var paragraphNumbersStyle = "Paragraph Numbers";
var objectStyle = "Paragraph Numbers";
var undoText = "Add paragraph numbers in margin";


/********************* Don't edit the script beyond this point *******************/


app.doScript(init, void 0, void 0, UndoModes.ENTIRE_SCRIPT, undoText);

function init() {
    var doc = app.activeDocument;
    var style = doc.paragraphStyles.item(numberedParagraphStyle);

    app.findObjectPreferences.appliedObjectStyles = doc.objectStyles.item(objectStyle);
    var frames = app.findObject();

    for (var i = frames.length - 1; i >= 0; i--) {
        frames[i].remove();
    }
    
    app.findGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences.findWhat = '^.+$';
    app.findGrepPreferences.appliedParagraphStyle = style;
    var p, frame, ip;
    var paras = doc.findGrep();

    progress(paras.length);

    for (var i = paras.length; i > 0; i--) {
        p = paras[i - 1];
        
        progress.message("Processing paragraphs: " + i + " of " + paras.length + " paragraphs left.");
        progress.increment();

        p.insertionPoints[0].textFrames.add({
            appliedObjectStyle: doc.objectStyles.item(objectStyle),
            contents: i.toString()
        });
    }

    progress.close();
}

function progress(steps) {
    var b;
    var t;
    var w;

    w = new Window("palette", "Progress", undefined, {closeButton: false});
    t = w.add("statictext");
    t.preferredSize = [450, -1]; // 450 pixels wide, default height.

    if (steps) {
        b = w.add("progressbar", undefined, 0, steps);
        b.preferredSize = [450, -1]; // 450 pixels wide, default height.
    }

    progress.close = function () {
        w.close();
    };

    progress.increment = function () {
        b.value++;
    };

    progress.message = function (message) {
        t.text = message;
    };

    w.show();
}
11
  • I love this answer. Learned a few tricks for InDesign scripting. But I also believe that I found a few bugs: 1. The GREP search for "Numbered paragraphs" (resulting in the paras array) doesn't work if there are "Numbered paragraphs" immediately following each other. They just receive a number in the first paragraph. Perhaps search for .+\r? 2. The paragraphs get numbered backwards. The for loop should count from 0 and up instead. 3. Shouldn't progress.increment; be changed to progress.increment(); so the function gets called?
    – Wolff
    Jan 10, 2021 at 21:06
  • I can confirm that the script seems to work as intended if I fix the things I mentioned above. If you reverse the for loop you don't need the count variable anymore (which was actually causing the problem to begin with because it counts the other way than i).
    – Wolff
    Jan 10, 2021 at 21:13
  • @Wolff The numbering from the end is intentional – adding the anchored frame adds a character, and insertion points are essentially numbered from zero at the start of the story, across paragraphs, so if you add from the start, your insertion points move one backwards for each insertion, eventually ending up in previous paragraph. At least that happens when you use doc.paragraphs.everyItem().getElements(). I haven’t tested whether it’s the same with the GREP solution, but I assume it probably is. Since the number added is the numeric index, the numbers on the page should still be right. Jan 10, 2021 at 21:14
  • 2
    Very nice, Janus! Thanks for sharing. Already +1, but this.. this I think deserves a bounty when possible :)
    – Scott
    Jan 10, 2021 at 22:21
  • 1
    @Jacob Did you make sure to change Numbered paragraphStyle in the first line to the name of the paragraph style you want to number in your InDesign document (i.e., the style where there’s a ¶ at the beginning of each paragraph)? You have to write the name exactly the same as how it’s written in the Paragraph Style Options, including small/capital letters, spaces, etc., and you have to keep the quotes when updating the name in the script. You have to do this with all three first lines in the script, otherwise it won’t know which paragraph and object styles to look for and apply. Jan 11, 2021 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.