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

Discuss the word processor

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

Postby tommydog » Wed Jan 13, 2021 2:26 am

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
tommydog
 
Posts: 19
Joined: Wed Jan 13, 2021 2:24 am

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

Postby robleyd » Wed Jan 13, 2021 3:47 am

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
Apache OpenOffice 420m2(Build:9821) - Slackware 14.2 - 64 bit
LibreOffice 6.4.6.2 (SlackBuild for 6.4.6 by Eric Hameleers) - Slackware 14.2 - 64 bit
Apache OpenOffice 4.1.4 - Windows 7 Virtual machine
User avatar
robleyd
Moderator
 
Posts: 4199
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

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

Postby tommydog » Wed Jan 13, 2021 11:03 am

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
tommydog
 
Posts: 19
Joined: Wed Jan 13, 2021 2:24 am

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

Postby JeJe » Wed Jan 13, 2021 1:16 pm

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 58 times
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1705
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby tommydog » Wed Jan 13, 2021 1:45 pm

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
tommydog
 
Posts: 19
Joined: Wed Jan 13, 2021 2:24 am

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

Postby floris v » Wed Jan 13, 2021 1:49 pm

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.
LibreOffice 6.4 on Linux Mint, LibreOffice 7.2.2.2 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
User avatar
floris v
Volunteer
 
Posts: 4277
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

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

Postby JeJe » Wed Jan 13, 2021 2:58 pm

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   Expand viewCollapse view
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 60 times
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1705
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby JeJe » Wed Jan 13, 2021 3:08 pm

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   Expand viewCollapse view
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
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1705
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby John_Ha » Wed Jan 13, 2021 5:41 pm

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.
John_Ha
Volunteer
 
Posts: 8702
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

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

Postby tommydog » Wed Jan 13, 2021 7:45 pm

Thank you for your help with this
OpenOffice 4.1.8 on Windows 10
tommydog
 
Posts: 19
Joined: Wed Jan 13, 2021 2:24 am

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

Postby JeJe » Wed Jan 13, 2021 8:59 pm

Another probably very awkward method would be to use multiple columns. Either 3 columns or two plus normal line numbering.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1705
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby John_Ha » Wed Jan 13, 2021 9:52 pm

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.
John_Ha
Volunteer
 
Posts: 8702
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

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

Postby JeJe » Wed Jan 13, 2021 11:34 pm

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.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1705
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby John_Ha » Thu Jan 14, 2021 2:10 am

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.
John_Ha
Volunteer
 
Posts: 8702
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

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

Postby tommydog » Thu Jan 14, 2021 2:47 pm

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


Code: Select all   Expand viewCollapse view
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
tommydog
 
Posts: 19
Joined: Wed Jan 13, 2021 2:24 am

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

Postby JeJe » Thu Jan 14, 2021 2:54 pm

Ah... I see... you just wanted pages of the numbers not bounding any text... yeah that's easy.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1705
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby John_Ha » Thu Jan 14, 2021 6:00 pm

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 1151 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.
John_Ha
Volunteer
 
Posts: 8702
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK


Return to Writer

Who is online

Users browsing this forum: No registered users and 13 guests