3

By doing the following:

  • right-clicking the Normal paragraph style,
  • Modify...
  • [Format], Numbering...
  • [Define new number format...]
  • Number style: 1,2,3...; Number format: 1; Alignment: Right

and

  • right-clicking the Normal paragraph style,
  • Modify...
  • [Format], Paragraph...
  • Indentation left: -0.25"; Special: Hanging; by: 0.25"

I managed to create a style which continually numbers paragraphs, looking as follows:

enter image description here

What I want, however, is that the paragraph numbers always appear on the outer edge, i.e., the numbers 12 to 14 should appear on the right edge instead of at the left edge like the previous page.

Like images, tables etc., I must be able to refer to any paragraph number ("as per paragraphs 117 ff."), which is possible with above approach.

Intention: printed report consisting of thousands of paragraphs, to be discussed in great detail, immensely being facilitated by being able to refer to paragraph numbers. And it's simply ugly to have the (possibly partially obscured) numbering to the left on odd numbered pages.

Is such a numbering style even possible?

(Using MS Word 2019 Professional: perhaps we should add a tag for it?)

  • Please add details about how you defined this style. – harrymc Oct 21 '18 at 10:32
  • 1
    @harrymc, done. – Herb Oct 21 '18 at 10:49
  • See if this solution works for you. – harrymc Oct 21 '18 at 11:13
  • 1
    @harrymc, thanks for the suggestion, but that solution is concerned wirh line numbering, not paragraph numbering. My paragraphs contain between 1 and about quarter page length paragraphs... – Herb Oct 21 '18 at 11:59
  • 1
    @harrymc, not really. Also, it involves tricks, like changing to Hebrew before printing, then changing back. I simply want a paragraph numbering, which I can have, as shown. Ideally it would be as asked, if even possible. – Herb Oct 21 '18 at 12:28
0

I saw your question on Stack Overflow, where it was really "too broad" as formulated, but it intrigued me.

It can be done, although not completely automatically, manually and/or with VBA.

  1. Select any (an empty) paragraph and apply a Frame to it. You can find the Insert Frame command in the Developer tab of the ribbon, Controls group, Legacy controls. It's the fourth control from the left

enter image description here

  1. Size the frame, apply the font size you want for the numbers, etc.
  2. Right-click the frame to get to the Format Frame dialog box. For the horizontal position select Outside relative to the Page and fine-tune the distance from the text if necessary. Vertical position should be 0 relative to the paragraph. Make sure "Move with text" and "Lock anchor" are activated. When the dialog box is confirmed the framed paragraph should move to the outside margin of the immediately following paragraph.
  3. Create a new style from this paragraph - it will include the Frame definition.
  4. Test the style by typing in or selecting another empty paragraph and applying the style to it.

The numbering can be generated by placing an SEQ field in each frame, then updating the fields in the document.

At this point, manually, it would be possible to generate the numbering. A long task, of course, for a large document. The following code will cycle all paragraphs in a document, inserting an empty paragraph, an SEQ field and formatting it with the style. At the end, all the fields are updated.

This will, almost certainly (based on the screen shots you show) insert more numbers than you want. You can either go through and delete them manually or alter the code to ignore paragraphs that meet the particular criteria that should not be numbered, or alter the code to skip those paragraphs when generating the frames.

In this code, the style for the frames is named NrPara; if you use a different name you need to change this.

Sub NumberParas()
    Dim doc as Word.Document
    Dim Para As Word.Paragraph
    Dim rngPara As Word.Range, rngParas() As Word.Range
    Dim numParas As Long, counterPara As Long
    Dim numParaStyle As Word.style
    Dim rngNumPara As Word.Range
    Dim sSEQ As String

    sSEQ = "SEQ ParaNum"
    Set doc = ActiveDocument
    numParas = doc.Paragraphs.Count
    ReDim rngParas(numParas - 1)

    'Get an array of the paragraph ranges
    For counterPara = numParas To 1 Step -1
        Set Para = doc.Paragraphs(counterPara)
        Set rngPara = Para.Range
        Set rngParas(counterPara - 1) = rngPara
    Next

    'Insert a paragraph above each existing one, format and insert SEQ field
    For counterPara = LBound(rngParas) To UBound(rngParas)
        Set rngPara = rngParas(counterPara)
        With rngPara
            .InsertBefore vbCr
            .Collapse wdCollapseStart
            .Fields.Add rngPara, wdFieldEmpty, sSEQ, False
            rngPara.style = "NrPara"
        End With
    Next
    doc.Fields.Update
End Sub
0

Creating a dedicated style

This style implements consecutive numbers on the outer page margins, top-aligned with the paragraph being numbered. An independent style needs to be created for these marginal numbers.

Create some paragraphs with style Normal. Before such a paragraph, enter an empty paragraph. Position the cursor on the new empty paragraph. In the Styles window, click the New Style button. In the Create New Style from Formatting window, name the new style Marginal Number. The Style type is Paragraph, and both the Style based on and Style for following paragraph fields are set to Normal. As font color I use a medium gray, so that the numbering doesn't distract from the text too much. The text flow is set to centered.

In the dropdown list labeled Format select Frame..., and in the Frame window select Text Wrapping Around. The Horizontal position is Outside, relative to Page. The Distance from the text should be 1 cm in order to not distract too much from reading the text. Make sure the Vertical position is 0 relative to Paragraph (this is the default). Also make sure to enter a minimum Height (in the Size group), in order to prevent showing the marginal number on the previous side, while the paragraph itself shows on a new side. I use At least 2 cm here (I am using metric measurement units). Make sure to have the checkbox Move with text ticked. Click OK.

In Format select Numbering..., and in the Numbering and Bullets window, click on the button labeled Define new number format.... Choose number style 1,2,3..., but make sure that in Number format you have just the digit 1, not an ending dot or anything else. In Alignment choose Centered again. Confirm all windows.

In View, Views select Print Layout in order to see the effect of the numbering. Just enter a paragraph before an existing paragraph already containing text and apply the new style to it: the new marginal number will be added on the outer margin, top-aligned with the following paragraph.

There's one more thing to do. Place the cursor in the marginal number frame, just after the number. There is some space which needs to be removed. Right-click to obtain the context menu, and select Adjust list indents.... In the appearing window, set both the Number position as well as the Text indent to 0, and Follow number with to Nothing. After clicking OK Word warns that these changes will be applied to the style Marginal Number, which is precisely what we want, so click Yes. You will notice, that the frame containing the marginal number is much narrower now, i.e., we gained more space for larger numbers.

Note, that these marginal numbers can be refered to via References, Captions, Cross-reference; they appear as a simple number.

Create a macro for marginal numbers

The whole procedure to add a marginal number is somewhat tiresome: position the cursor at the beginning of a paragraph, press enter to obtain a new empty paragraph, reposition the cursor in the new paragraph, click on the new style to apply it. A macro can automate these tasks.

Provide some paragraphs with text, so that the macro can be recorded. Position the cursor before the first character of a not yet numbered paragraph. Start a new macro recording with Views, Macros, Record Macro..., and in the Record Macro window, name the macro sensibly (here: InsertMarginalNumber), then select Keyboard. In the Customize Keyboard window, assign a new key combination which shall be used to execute the macro. I chose Ctrl+M with the M standing for Marginal Number. (Note, that this will overwrite the original shortcut used to indent a paragraph. If you are used to that shortcut, it is advisable to use another shortcut.) Click the buttons Assign and then Close.

Now the macro is recording. Press Enter, then the Arrow left key, apply the style Marginal Number, then press the Arrow right key. Stop recording the macro via View, Macros, Stop Recording. To verify the macro, position the cursor at the beginning of a yet unnumbered paragraph, then press Ctrl+M.

This is the code of the recorded macro:

Sub InsertMarginalNumber()
    Selection.TypeParagraph
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.Style = ActiveDocument.Styles("Marginal Number")
    Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub

To apply, move the cursor at the beginning of a paragraph, then press Ctrl+M: there's your marginal number on the outer margin.

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.