I want a paragraph inside a cell, but I get a stray carriage return which pushes down the text by one line:
My code:
from docx import Document
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.shared import Cm
document = Document()
document.add_heading("The Heading", 1).alignment = WD_ALIGN_PARAGRAPH.CENTER
table = document.add_table(rows=0, cols=2)
table.style = 'Table Grid'
for i in range(3):
row_cells = table.add_row().cells
row_cells[0].text = 'row {}, col 1'.format(i)
row_cells[0].width = Cm(3)
row_cells[1].width = Cm(8)
p = row_cells[1].add_paragraph()
p.add_run('This is an example of')
p.add_run(' some text').bold = True
p.add_run(' in a table cell.')
document.save('test.docx')
How can I get the cell text to align at the top of the cell without the stray CR? And how should I be setting the cell widths to 3 cm and 8 cm: setting _Cell.width
isn't respected.