A long table in Word spills onto page two, and from there on the reader sees rows of numbers and names with no column titles above them. They scroll back to page one to check which column is which, or you end up copying the header row by hand and fixing it every time the page break moves.
TL;DR: Click the table's top row, go to the Table Layout tab, and turn on the header-row repeat option.
Steps
- Click in the header row of the table (the top row with the column names).
- Open the Table Layout tab and turn on the option that repeats the header row. In desktop Word it's called Repeat Header Rows. Our test used the Korean version of Word for the web, where the button has a different name, so the English label in the web version may vary.
- The header row now appears at the top of the table on every following page.
Edit the header text (for example, "Sales" to "Units sold") and the repeated copies on later pages change with it, because they are the same row displayed again, not copies.
Checked in the free Word for the web.
Another way in desktop Word
Right-click the header row, choose Table Properties, open the Row tab and tick "Repeat as header row at the top of each page." It sets the same thing.
Common mistakes
The repeating row has to be the first row of the table. You can repeat the first two or three rows together, but you can't pick a row from the middle.
Word repeats the header at automatic page breaks. If you insert a manual page break inside the table, Word splits it into two tables and the header won't follow.
Copying the header row onto the next page by hand looks fine until someone adds a few rows. Then the copied header ends up in the middle of page two.
Setting it from python-docx
python-docx has no direct property for this, but the setting is a single XML flag on the row, and the common workaround is to add it yourself:
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
tr_pr = table.rows[0]._tr.get_or_add_trPr()
flag = OxmlElement("w:tblHeader")
flag.set(qn("w:val"), "true")
tr_pr.append(flag)
That's worth adding to any script that writes reports with long tables, since the person reading the output will hit the same page-two problem.
AI assisted in writing this article. The steps were checked in Word for the web.
Top comments (0)