none
Tables and forcing no page breaks RRS feed

  • Question

  • I have two tables.  The last two rows of the first table will always be on the same page because I am setting the “Keep With Next” property for these rows.  The second table consists of only about three rows.  The two tables are separated by a blank line.  

    I want to make sure there will be no page break between the two tables and no page breaks in the second table at all.  So, I want force the last two lines of the first table, the blank line, and the entire second table to be on the same page.

    Does anyone know how I can do this?

    Friday, April 15, 2011 1:16 PM

Answers

  • Hi Ryno,

    If all your cells in column 1 of table 1 have the 'keep with next' property and table 2 also has the 'keep with next' property in all except the last cell in column 1 then, if the combined size of these two tables grows too much to fit on one page, something's got to give. Word won't force a predefine # of rows from table 1 to accompany table 2 to the next page unless there's a discontinuity in the 'keep with next' property somewhere in table 1.

    So, if you format the table 1 header and the first few rows following with the 'keep with next' property, then apply the 'keep with next' property to just the last few rows of that table, and apply the 'keep with next' property to both the intertable paragraph and all except the last row of table 2, that should ensure that, when table 2 won't fit on the same page as table 1, it takes a few rows of table 1 with it to the next page.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by Bruce Song Monday, May 2, 2011 8:25 AM
    Wednesday, April 20, 2011 9:20 AM

All replies

  • Hi Ryno,

    Simply extend the 'keep with next' formatting to the second table. Ideally, you'll leave the last paragraph in each cell in the second table without that formatting; otherwise the second table will try to 'keep with' the following paragraph as well.


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Friday, April 15, 2011 1:39 PM
  • I have implemented the approach you suggested by extending the 'keep with next' to the following table, and to the blank line between the two tables.  Very specifically, this is what my table looks like:

    Note that the '*' character signifies a cell with the 'Keep Next' property set.

     

    c1 c2 c3 (First row of table 1)

    ... (Lots more lines)

    c1* c2 c3 (Second to last row)

    c1* c2 c3 (Last Row of table 1)

    blank line*

    c1* c2 c3 (first row of table 2)

    c1* (only one column in the second row of table 2)

    c1 (only one column in the third row of table 2 - which is the last row of table 2)

     

    Here are my observations - let's set an initial condition the last row of table 2 is the last row of information that fits on the page.

    1. When one more row is added to table 1, the last row of table two is pushed to the next page (it should force the last two rows of table one, the line feed, and the entire table two to the next page).

    2. An additional row pushes the next row of table two to page two.  This continues until the blank line is pushed to page 2.

    3. After the blank line is pushed to page 2, an additional line in table 1 will successfully push the last two lines of table 1 to the page 2.

     

    A few notes that may or may not be important.  

    1. Table 1 has header rows that are set to repeat on every page that the table spans, and this does appear to work fine.

    2. I am programmatically constructing the Word document in C# using the DocumentFormat.OpenXml.Wordprocessing DOM.

    3. I am using Word 2007.

     

    Do you have any additional techniques I can try?

     

    Friday, April 15, 2011 2:20 PM
  • Dear Ryno,

    Could you upload a demo to the skydrive so that I can help you research this problem? By the way, did you use Open XML SDK to process the document? If so, it will be nice if you can show us the code snippet?

    Regards,


    Be happy.
    • Edited by Mike_HelpYou Wednesday, April 20, 2011 9:01 AM typo
    Wednesday, April 20, 2011 9:01 AM
  • Hi Ryno,

    If all your cells in column 1 of table 1 have the 'keep with next' property and table 2 also has the 'keep with next' property in all except the last cell in column 1 then, if the combined size of these two tables grows too much to fit on one page, something's got to give. Word won't force a predefine # of rows from table 1 to accompany table 2 to the next page unless there's a discontinuity in the 'keep with next' property somewhere in table 1.

    So, if you format the table 1 header and the first few rows following with the 'keep with next' property, then apply the 'keep with next' property to just the last few rows of that table, and apply the 'keep with next' property to both the intertable paragraph and all except the last row of table 2, that should ensure that, when table 2 won't fit on the same page as table 1, it takes a few rows of table 1 with it to the next page.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by Bruce Song Monday, May 2, 2011 8:25 AM
    Wednesday, April 20, 2011 9:20 AM
  • Hi Rayo,

    Have you resolved your problem yet, and do the suggestions help you? If you still have any concern on the thread, just feel free to follow up. We are happy to help with you.

    Best Regards,



    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 26, 2011 6:29 AM