[Solved] Line numbering on left and right of page in Writer?

Discuss the word processor
Post Reply
tommydog
Posts: 19
Joined: Wed Jan 13, 2021 2:24 am

[Solved] Line numbering on left and right of page in Writer?

Post by tommydog »

line numbering on left and right of page in Writer?

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 writer? Can I do this natively, or is there a macro that would work?
numbers.png
Last edited by Hagar Delest on Thu Jan 14, 2021 3:41 pm, edited 2 times in total.
Reason: tagged solved.
OpenOffice 4.1.8 on Windows 10
User avatar
robleyd
Moderator
Posts: 5081
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: line numbering on left and right of page in Writer?

Post by robleyd »

Cross posted at AskLibreOffice.

If you cross post, please note that you have done so, otherwise it leads to several discussions and a waste of time because several identical answers may be posted by different users.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
tommydog
Posts: 19
Joined: Wed Jan 13, 2021 2:24 am

Re: line numbering on left and right of page in Writer?

Post by tommydog »

robleyd wrote:Cross posted at AskLibreOffice.
I posted in both forums, as it is relevant to each program, and each program may have a different user base. I also have Open office and Libre office installed on my computer, so why not ask in both places? I have also not received a reply on either forum that fully answers my question, so why not ask in both places? Of course if I receive a reply that answers my question, I will update the threads.
OpenOffice 4.1.8 on Windows 10
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Line numbering on left and right of page in Writer?

Post by JeJe »

If you want the same numbering on every page you can use frames attached to the header (as in the attached document)
If you want different numbering on each you can have different frames attached to each page.
Attachments
frame in header.odt
(9.38 KiB) Downloaded 139 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
tommydog
Posts: 19
Joined: Wed Jan 13, 2021 2:24 am

Re: Line numbering on left and right of page in Writer?

Post by tommydog »

Thank you JeJe for your reply, but how do I automatically fill those frames with numbers for every line (like line numbering). There are a few hundred pages, so it would be very tedious to do manually
OpenOffice 4.1.8 on Windows 10
User avatar
floris v
Volunteer
Posts: 4430
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: line numbering on left and right of page in Writer?

Post by floris v »

tommydog wrote:
robleyd wrote:Cross posted at AskLibreOffice.
I posted in both forums, as it is relevant to each program, and each program may have a different user base. I also have Open office and Libre office installed on my computer, so why not ask in both places? I have also not received a reply on either forum that fully answers my question, so why not ask in both places? Of course if I receive a reply that answers my question, I will update the threads.
You should read all of robleyd's post, not just the first line. He adds an explanation and it's a good one. You don't want to waste the time of other people, so while it's okay to cross post, you should always add links to the other places where you post.
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Line numbering on left and right of page in Writer?

Post by JeJe »

A macro could be written to add numbers to frames and insert frames but you'll need to say more about what it is you want to add the lines to/post a sample. What's going to work will depend on what that is.

Another approach is given in the other thread. This similar macro will add the numbers at the beginning and end of the lines with the provisos:

There's no line wrapping
All the paragraphs have a right aligned tab positioned at the right margin
Edit: and there's room for the numbers


Code: Select all

Sub Main
vc = thiscomponent.currentcontroller.viewcursor
vc.gotorange (thiscomponent.text.start,false)
do
no = no+1
vc.gotostartofline false
vc.gotoendofline true
vc.string = no & vc.string & chr(9) & no
ret =vc.godown(1,false)
if ret = 0 then exit do
loop
End Sub
Attachments
sample.odt
(11.12 KiB) Downloaded 123 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Line numbering on left and right of page in Writer?

Post by JeJe »

Thinking a bit more, the best approach is possibly run this macro which puts numbers at the start of every line whether they're wrapped or not. And set the line numbering to right position, interval 1 for the right aligned numbers.

Code: Select all

Sub Main
vc = thiscomponent.currentcontroller.viewcursor
vc.gotorange (thiscomponent.text.start,false)
do
no = no+1
vc.gotostartofline false
vc.gotoendofline true
vc.string = no & " " & vc.string
ret =vc.godown(1,false)
if ret = 0 then exit do
loop
End Sub
Edit: slightly simplified macro, added space after number
Edit2: reverted to earlier version with added space
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Line numbering on left and right of page in Writer?

Post by John_Ha »

The left can be done as usual or:

Anchor "images with the numbers" in the header or footer. They appear on every page.
Set a "blank background image with the numbers" to each page style.
Add a watermark with the numbers. Most printers allow it at printing too.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
tommydog
Posts: 19
Joined: Wed Jan 13, 2021 2:24 am

Re: Line numbering on left and right of page in Writer?

Post by tommydog »

Thank you for your help with this
OpenOffice 4.1.8 on Windows 10
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Line numbering on left and right of page in Writer?

Post by JeJe »

Another probably very awkward method would be to use multiple columns. Either 3 columns or two plus normal line numbering.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Line numbering on left and right of page in Writer?

Post by John_Ha »

JeJe wrote:Another probably very awkward method would be to use multiple columns. Either 3 columns or two plus normal line numbering.
I don't think that will work because, when text from the centre column spills, it does not go to the next page centre column - it goes into the right column. Every edit or change would require the numbers to be adjusted - it wouldn't merely be awkward, it would be a nightmare. :crazy:
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Line numbering on left and right of page in Writer?

Post by JeJe »

John_Ha - yep... it would make no sense except once for a finished document needing no further editing. Same with the methods that add the numbers directly before and after in the main text.

Edit: the 3 column method could be combined with the frame one, having a single frame in the background for each page with both columns of numbers. The problem with the frame methods is if heights of lines vary it will be complicated matching that.

Edit 2
Or we could have one frame in the background for both lots of numbers without columns using the right aligned tab method.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Line numbering on left and right of page in Writer?

Post by John_Ha »

JeJe wrote:John_Ha - yep... it would make no sense except once for a finished document needing no further editing.
When you find one of those treasure it - they are a lot rarer than hens' teeth. :super:
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
tommydog
Posts: 19
Joined: Wed Jan 13, 2021 2:24 am

Re: Line numbering on left and right of page in Writer?

Post by tommydog »

This is what I used in the end and it works great:

Code: Select all

Sub twoColNums

Dim i, s 

Do 
    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
OpenOffice 4.1.8 on Windows 10
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Line numbering on left and right of page in Writer?

Post by JeJe »

Ah... I see... you just wanted pages of the numbers not bounding any text... yeah that's easy.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: [Solved] Line numbering on left and right of page in Wri

Post by John_Ha »

JeJe wrote:Ah... I see... you just wanted pages of the numbers not bounding any text... yeah that's easy.
I misunderstood too. If it's just the numbers needed:

1. Create the number sequence in adjacent columns a spreadsheet
2. Edit > Copy the range required
3. Edit > Paste special > Unformatted text .., into a text document.

All done.
Clipboard02.png
Clipboard02.png (3.88 KiB) Viewed 2422 times
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Post Reply