Page 1 of 1

[Solved] Remove empty lines between tables

Posted: Tue Feb 13, 2024 10:19 am
by Mr.Dandy
Hello,

I'm try to use this regex

Code: Select all

^$
But nothing is found

Re: Remove empty lines between tables

Posted: Tue Feb 13, 2024 10:58 am
by erbsenzahl
It seems that there is a special connection of tables and their trailing paragraphs.

EDIT
You can manually delete the trailing paragraphs (DEL key or in the last table cell shortcut CTRL+SHIFT+DEL) but not the trailing paragraph of the (stand alone) last table.
To delete the trailing paragraph of the last stand alone paragraph you can work on OpenOffice 3.x, but after saving/closing and opening again it will be automatically generated again...

Re: Remove empty lines between tables

Posted: Tue Feb 13, 2024 11:16 am
by RoryOF
From memory every table has a trailing line, which cannot be removed. I think it can however be selected and reduced to 2 points, the minimum allowed in this case.

Re: Remove empty lines between tables

Posted: Tue Feb 13, 2024 11:31 am
by RoryOF
erbenzahl is correct: experiment shows one can manually delete each inter table paragraph mark, but not the final one; that however can be reduced to two points.

Re: Remove empty lines between tables

Posted: Tue Feb 13, 2024 5:31 pm
by JeJe
You can put the tables in frames and align them together or even overlap them.

Re: Remove empty lines between tables

Posted: Tue Feb 13, 2024 6:27 pm
by Hagar Delest
Actually, there is a trick to "remove" the last paragraph below a table: type at least a character (can be a space, or better a string like "last line") and set the character properties of that "paragraph" to hidden.
:ugeek:

Please add [Solved] at the beginning of the title in your first post (top of the topic) with the 🖉 button if your issue has been fixed.

Re: Remove empty lines between tables

Posted: Tue Feb 13, 2024 7:02 pm
by MrProgrammer
RoryOF wrote: Tue Feb 13, 2024 11:16 am From memory every table has a trailing line, which cannot be removed.
Yes, a table must be contained in a paragraph, and every paragraph requires a paragraph properties marker (the ¶) at the end. If the table is the last element in the paragraph, the marker must be placed after the table because it is not possible to place content left or right of a table. However one can prevent the paragraph marker after the table from being displayed on the page. Several suggestions are in the replies above.

Mr.Dandy wrote: Tue Feb 13, 2024 10:19 amRemove empty lines between tables
To avoid space between tables:
• You can put multiple tables in the same paragraph (put cursor before paragraph's ¶ and use Insert → Table)
• You can put multiple-subtables in a paragraph consisting of a 1-row 1-column table
202402131011.odt
(11.71 KiB) Downloaded 139 times

Using the latter method you can copy/paste the text of your attachment into the 1-row 1-column table and then remove the paragraph markers that you don't want so the tables don't have space between them. The 1-row 1-column table must be contained in a paragraph, but the sub-tables inside don't require paragraph markers because their paragraph is the one with the outer table. I will admit that sub-tables can be confusing and may be difficult to work with.

Here is earlier discussion about the empty line after a table.
[Solved] Undeletable page when filling whole page with table

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.

Re: Remove empty lines between tables

Posted: Wed Feb 14, 2024 12:18 pm
by JeJe
So using MrProgrammer's method:

select the table and do a copy
delete the table
On the paragraph below the previous table use Table menu/insert table of the same size
paste what was copied from the old table into the new one.

*

A slight variation on Hagar Delest's method would be to create a paragraph style with the hidden font effect property then that style can be applied to the line without any text being needed. And it can be reversed easily to put the lines back by removing the hidden font effect from the style.

Re: Remove empty lines between tables

Posted: Wed Feb 14, 2024 12:28 pm
by Hagar Delest
JeJe wrote: Wed Feb 14, 2024 12:18 pm A slight variation on Hagar Delest's method would be to create a paragraph style with the hidden font effect property then that style can be applied to the line without any text being needed. And it can be reversed easily to put the lines back by removing the hidden font effect from the style.
The best method in the end IMHO. Because you can display again those lines very easily by accessing that custom paragraph style from the Stylist, no need to play with the display options to make the hidden characters visible.
I'm not sure it was possible to set the hidden settings to a paragraph style in the past.

Re: Remove empty lines between tables

Posted: Wed Feb 14, 2024 3:16 pm
by Mr.Dandy
As I said in my first post, I would like to remove only empty lines between two tables
Expected result below:
capture.gif
capture.gif (3.55 KiB) Viewed 6384 times


This can be done manually.
But my document is of course more complex than the one shown as example.
 Edit: Moved from Writer forum to Macros and UNO API because Mr.Dandy wants a macro. -- MrProgrammer, forum moderator  

Re: Remove empty lines between tables

Posted: Wed Feb 14, 2024 4:49 pm
by RoryOF
Why does it arise that you wish to compact several tables? Why not make one longer table to contain all the information?

Re: Remove empty lines between tables

Posted: Wed Feb 14, 2024 5:20 pm
by Hagar Delest
Mr.Dandy wrote: Wed Feb 14, 2024 3:16 pm But my document is of course more complex than the one shown as example.
Actually, that would have been useful in the first post.
Now what I understand is that you have a possibly long document with lots of tables, that may have different layouts, and you want to remove the empty paragraphs between them at once. Since they already exist, having a single table in the first place is not the point.

You can try the AltSearch extension, it may fond those empty paragraph between tables.
Else, the only way I see is to make a macro with a cursor that goes to a table, then to its last cell, then go right to go to the next paragraph then select the paragraph, if null, then delete, then go to the next table (if cursor is not in the next table already).

Re: Remove empty lines between tables

Posted: Wed Feb 14, 2024 5:31 pm
by RoryOF
If one is editing an existing document, then the table compaction makes sense. However, it may be difficult to label each of the component tables when they are all close together. Typically, each table in a document is given a unique name for reference from the accompanying text.

Re: Remove empty lines between tables

Posted: Thu Feb 15, 2024 1:45 am
by JeJe
This works on your sample file. It removes the blank line if there is one following every table provided that line isn't itself in a table. If there are tables with blank lines following tables that you don't want to remove you'll need to adapt the code for that.

Code: Select all

Sub RemoveLines

for i = 0 to thiscomponent.texttables.getcount -1
t = thiscomponent.texttables.getbyindex(i)
tc= t.getanchor.text.createtextcursorbyrange( t.getanchor.end)
tc.goright 1,false
if isempty(tc.texttable ) then
with tc.createenumeration.nextelement
if .string = "" then .dispose
end with
end if
next

End Sub
Edit: oops didn't add test to see if paragraph following table was empty - corrected.

Re: Remove empty lines between tables

Posted: Sat Feb 17, 2024 6:22 pm
by Mr.Dandy
The macro works fine. Thanks
That's solved the regex issue.