Keep with next row (in tables)

Post here questions and problems related to editing and publishing DITA content.
bvlach
Posts: 3
Joined: Thu May 02, 2024 1:35 am

Keep with next row (in tables)

Post by bvlach »

Hi team! I found the threads about how to make sure that a row does not split across pages and about how to not allow shorter tables to break across pages at all. But I can't find any info about how I might "keep with next" row. (This is for rendering out in PDF.)
For example, in a table with many rows (50+), we break it up with some "merged rows" that serve as section headers and I want to make sure that these section headers don't get orphaned at the bottom of a page without at least one row beneath them from the section it represents. If there isn't enough room for at least one row beneath it, then I want it to push to the next page in the PDF. Is there a way to do this?
julien_lacour
Posts: 664
Joined: Wed Oct 16, 2019 3:47 pm

Re: Keep with next row (in tables)

Post by julien_lacour »

Hello,

Are your "merged rows" merged on multiple columns, multiple rows or both?
If they are expanding on multiple columns, you can use the following CSS rule:

Code: Select all

*[class ~= "topic/row"]:has(*[class ~= "topic/entry"][colspan]) {
  break-after:avoid;
}
Regards,
Julien
bvlach
Posts: 3
Joined: Thu May 02, 2024 1:35 am

Re: Keep with next row (in tables)

Post by bvlach »

Thank you so much for the quick response, Julien!
Unfortunately, I'm still struggling with where to insert this. My XML file looks like this and this is where I want to insert the command to "keep-with-next" (yes, it's a single row that spans all columns and I want it to jump to the next page to stick to at least the first row of this section). And I'm also interested in a way to specify for the entire table to not let any rows break across a page. Can this be done from the Oxygen/XML?

Here's the row I'm trying to control:

Code: Select all

	<entry>
		<p>√</p>
	</entry>
</row>
<row rowsep="1">
	<entry namest="1" nameend="newCol9">
		[b][u]<p id="id1073bd75-2950-4c80-a898-ddcc21ae3c1e"><tt>CN-Series Firewall</tt></p>[/u][/b]
	</entry>
</row>
<row rowsep="1">
	<entry colname="1">
		<p>CN-Series Small</p>
		<p>CN-MGMT Mem: 2GB</p>
		<p>CN-NGFW Mem: 2 to 2.5GB</p>
	</entry>
	<entry colname="3">
		<p>—</p>
	</entry>
	<entry colname="5">
		<p>√</p>
	</entry>
julien_lacour
Posts: 664
Joined: Wed Oct 16, 2019 3:47 pm

Re: Keep with next row (in tables)

Post by julien_lacour »

Hello,

You need to insert the above rule in a CSS stylesheet, then you need to use this stylesheet in the DITA Map PDF - based on HTML5 & CSS transformation scenario. For more information you can read this topic from our user guide.

To block page breaking inside rows you can use the following rule:

Code: Select all

*[class ~= "topic/entry"] {
  break-inside: avoid;
}
Just make sure your tables don't contain any row bigger than one page, the transformation will fail otherwise.

Regards,
Julien
bvlach
Posts: 3
Joined: Thu May 02, 2024 1:35 am

Re: Keep with next row (in tables)

Post by bvlach »

Hello and thanks again, Julien.
I will pass on this second piece of code to our rendering team to see if we're able to incorporate that for our PDFs. We'll definitely need to see if we have any tables with rows that break across pages, though, and either break those rows --or-- figure out how to toggle an "exception" to this rule for a given row where we can't avoid the page break. Can we do that (override this) for a single row in a table if we incorporate that code?

But I'm still not sure how to add the "keep-with-next" command to a single row (or several different, non-adjacent rows) in a table without having that condition apply to all rows (that would be a "keep-entire-table-on-one-page" which we never work in our reference files). If we place that code into the CSS, won't it apply to all rows? And if that's the point and then we can toggle on/off that action for a single row in the XML/source file, how would I toggle it?
julien_lacour
Posts: 664
Joined: Wed Oct 16, 2019 3:47 pm

Re: Keep with next row (in tables)

Post by julien_lacour »

Hello,

The second rule (with break-inside: avoid) indicates that a page break isn't possible inside a table cell, but it is still possible to break between two different rows. I think you can keep this rule for all cells inside a table. If you want to control page breaks as "exceptions", you can remove this rule and you can mark the rows with the outputclass="page-break-avoid" attribute:

Code: Select all

<row outputclass="page-break-avoid">
    <entry>Gardenia</entry>
    <entry>perennial</entry>
    <entry>acidic</entry>
</row>
There is a default CSS rule that will set break-inside: avoid for these rows, as explained in our user guide.

The first rule I gave you only disallow page breaks for rows having columns merged together, *[class ~= "topic/row"]:has(*[class ~= "topic/entry"][colspan]) means:
Any element with class containing topic/row (basically a row) having an element with class containing topic/entry (basically a cell) and colspan attribute".
If you want this rule to apply on other rows, you can mark them with your custom outputclass:

Code: Select all

<row outputclass="keep-with-next">
    <entry>Gardenia</entry>
    <entry>perennial</entry>
    <entry>acidic</entry>
</row>
The CSS rule will then become:

Code: Select all

*[class ~= "topic/row"][outputclass ~= "keep-with-next"],
*[class ~= "topic/row"]:has(*[class ~= "topic/entry"][colspan]) {
  break-after:avoid;
}
Regards,
Julien
Post Reply