Ask Your Question

line numbering on left and right of page in Writer?

asked 2021-01-13 01:19:35 +0100

tommydog gravatar image

I want to create a document of a few hundred pages, where continuous line numbers appear on the left and right of the page. Below is an example of what I want to achieve (although I want to specify a different starting number than 1). How can I do this in Libre Office writer? Can I do this natively, or is there a macro that would work?

image description

edit retag flag offensive close merge delete


You can certainly do it left or right side (or inner or outer). Both sides is not listed as a possibility in Tools > Line Numbering. You might need a macro

Earnest Al gravatar imageEarnest Al ( 2021-01-13 02:39:30 +0100 )edit

Do you have an example of a macro that I could use?

tommydog gravatar imagetommydog ( 2021-01-13 10:12:19 +0100 )edit
floris v gravatar imagefloris v ( 2021-01-13 12:59:13 +0100 )edit

1 Answer

Sort by » oldest newest most voted

answered 2021-01-13 13:14:28 +0100

CaveMan gravatar image

updated 2021-01-14 13:06:04 +0100

Here is a way you can do it.

  • From Styles drop down, click on More Styles, then expand Index category
  • Right click on User Index 1 and select Modify.
  • Under Fill Character, select None
  • Apply Style.

Here is a macro to generate the lines.

Sub twoColNums

Dim i, s 

    i = inputbox("How many lines you require?","Line Count")    
    s = inputbox("Starting number?","Starting number")
loop Until isNumeric(i) AND isNumeric(s)

Dim oText
oText = ThisComponent.Text

Dim n   

s = cLng(s)
i = cLng(i)

For n = s To s+i
    oText.insertString(oText.getEnd(), CHR$(13) & n & CHR$(9) & n , false)
Next n

Print "Done!"

End Sub
edit flag offensive delete link more


Thank you very much for the macro, it works well to generate the numbers, but the two sets of number colums are very close together (see picture below). How can the script be changed to space the two columns further apart?


Secondly, what would change on the script if I only wanted one column of numbers instead of two - I was thinking about this for another project that I have.

tommydog gravatar imagetommydog ( 2021-01-14 00:48:03 +0100 )edit

The issue with the numbers close together sounds like a style issue. Did you select and apply the style to the entire text? I suggest you play around with the style settings to get the desired look. As for single column, remove the either one of the two & n in the insertString command to get what you want.

CaveMan gravatar imageCaveMan ( 2021-01-14 12:15:03 +0100 )edit

Many thanks Caveman. I played around with the styles and it solved things. Just one more question, is it possible to specify the starting number? Say if I want it to start with number 36 instead of number 1. What would need to be changed in the script?

tommydog gravatar imagetommydog ( 2021-01-14 12:30:42 +0100 )edit

No problemo! See updated answer. Ooops fixed code issue. Should work fine now.

CaveMan gravatar imageCaveMan ( 2021-01-14 12:52:46 +0100 )edit

I just changed the n value to start at any number I want and it works great. Thanks so much.

tommydog gravatar imagetommydog ( 2021-01-14 13:45:16 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2021-01-13 01:19:35 +0100

Seen: 50 times

Last updated: Jan 14