Group a paragraph and a table so they don’t get split across pages

  Kiến thức lập trình

I am trying to add a caption for a table and then immediately after, add a table. Sometimes the table and caption get split across multiple pages because of table size, etc. Is there anything similar to https://python-docx.readthedocs.io/en/latest/api/text.html#docx.text.parfmt.ParagraphFormat.keep_together that can be used with both paragraphs and tables.

This is simply the format I am currently using. The caption comes first by way of a run in the paragraph, then comes the table. I need to make sure they get page-wrapped together.

from docx import Document

document = Document()

p = document.add_paragraph()
p.add_run('Table 1.1 -- Caption Text')

table = document.add_table(rows=2, cols=4)

New contributor

Ryan Godbey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

IF you just want to add comment have you tried using this should give you better line control .

'''
 ur para line1
 ur para line 2
 ...so  on?
'''

New contributor

SkewedGraph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

LEAVE A COMMENT