Making a long table with both repeating column titles AND section titles

5,307

I don't think there is going to be an easy way to achieve this layout, but I hope someone will think of a simpler approach…

I can think of two main approaches that you could take. I am assuming for the moment that there are no other headers/footers in the document. I have posted a document showing how Approach two would work at

https://www.dropbox.com/s/ngrhc8yds0umnoj/template_lorumipsum_mod1.docx

It would probably be better to look at that an see if it is even close to what you need before reading any further.

Approach one would I think require some VBA macros to make it work. What you would do is

  • Remove the repeating header row
  • Put that row as a single-row table in the document Header, which would then repeat
  • Use one table for each section, with the header row in each section repeated.

In that case, the main table column headings would always be above the "section headings", there would be no "cont." texts (although you may be able to fix that using a kludge), and you would have to deal with the fact that the column headings are separate from the data. That means two things:

  • there will be a vertical gap between the headings and the data (you can probably reduce that by ensuring that the headings row is taller than the document header)
  • the column widths may vary from table to table, screwing up the
    horizintal alignment. The only way I think you would be able to fix
    that easily would be to run a (VBA) macro that applied the same
    column widths to every row in every table. If your users aren't
    allowed to use VBA macros and/or the table layout can be more complex than your sample document suggests (e.g. you sometime merge/split
    columns) then that's probably not going to be a practical approach.

Approach two would be to keep the table layout you have, but use some Word field codes to insert a heading on each page.

I don't think the suggestion I made earlier to use { STYLEREF } fields is going to work, because they do not really provide continuation headers (for example, a STYLEREF field will typically display the text of the first header on the page, not the text of the header that is being continued).

The only way I know how to do this is to use some unusual SEQ fields to keep track of the section headers and to decide what should be displayed in each page header. To make this work, your users will have to be able to work with field codes (unfortunately, they look complicated and are rather easy to break). Also, Word works quite hard to keep its headers and footers up to date, and can sometimes get a bit confused when there are lots of fields with page-dependent values in those areas. So this tends not to work so well when a document gets larger - I'd check and see whether it works for your document type and size.

The specific approach I describe here makes some assumptions about what you want at the top of each page:

  • nothing at the top of the first page
  • nothing at the top of the page if the first row on the page is a section heading
  • otherwise, a continuation text from the previous page.

The document I posted has samples of the fields you need. For each section heading the user would need to insert two table rows containing a number of fields. That is completely impractical unless the user has a mechanism that allows them to do that easily. For example, if they set up the two rows as an formatted autocorrect entry called “seched”, then all they need do is type

seched

followed by a space

at the beginning of a table row, and the two rows would be included. There are other possibilities.

What I envisage is that your starting Word document would have (at least) the first (heading) row of the table, and the first section header, i.e. “Front Pages” in your sample document. a two-row block at the beginning of each subsequent section header. Ideally, the user would be able to insert the entire block, fields and all, using an autocorrect or perhaps a building block. They would then need to modify the text in the fields. If something like that is not feasible in your environment, this approach isn’t going to be practical either.

The key concepts for using fields in this situation are as follows: a. a field has a code and a result b. some samples of field codes are:

{ SEQ S \c }
{ PAGE }
{ SET T “some text” }
{ REF T }

c. The { } are special field code brace pairs that you can insert on Windows versions of Word using ctrl-F9. You can’t just type them usin gthe ordinary { and } characters on the keyboard d. You can toggle between “field codes” and “field results” view using Alt-F9

The results of the above four fields might be something like

4
2
(a SET field does not show a result. it just sets the value of a bookmark, in this case the bookmark “T”)
some text

e. Many field types do not update themselves. To see the correct results, you have to select them and press F9. Often, the simplest way to do this is to select the whole document using ctrl-A, then press F9. (going into Print Preview and out again is often suggested as an option, but in fact it does not update all field types). You may need to do this when, for example, your document’s pagination has changed. For this document type, what the user should really do is

  • show field results rather than codes
  • with the insertion point in the body of the document, use ctrl-A, then F9

    f. You can nest field codes in certain ways, for example the result of

    { IF { SEQ S \c } = 0 "S is zero' "S is not zero" }

should be “S is zero” when the current value of the SEQuence variable S is 0 and you have just updated all the fields. In this case, both pairs of { } need to be the “special field code braces”

g. In a document header or footer, the values of fields are generally equal to the value of the field as it would be if it were placed at the end of the body text in the page, not at the beginning of the page. SO we have to find a way to decide what a value is at the beginning of the page.

The method I propose uses the following fields:

In the first cell of the table heading, there are two fields:

{ SET T1 "" } (sets the bookmark T1 to an empty string)

{ SEQ S \r1 \h } (sets the sequence variable S to 1, hides the result)

Each section heading has the following fields, except that you replace the text in the { SET T } field by the heading text for that heading

{ SEQ S \h }{ SET T "Front pages" }{ T }{ SET "T{ SEQ S \c }" "...(cont.): { T }" }{ SEQ "P{ PAGE \#0 }N{ SEQ "P{ PAGE \#0 }" }" \r1 \h }

{ SEQ S \h } increases the value of S by 1 (in section 1, S will be 2) and the \h hides the result

{ SET T "Front pages" } sets bookmark T to “Front pages”.

{ T } (an abbreviation for { REF T } displays the value of bookmark T

{ SET "T{ SEQ S \c }" … } . In section 1, this will set the value of T2. In Section 2, it will set the value of T3, and so on. We set T2, T3 etc. to the text we want for the continuation notice in the page header. So you can either re-use the value of { T } and prepend "... (cont.): " to it, as I have done above, or you can write a completely different continuation text for each section. Again, that might require the user to modify the row height so they can see all the text in all the fields.

{ SEQ S \c } is the current value of sequence variable S.

{ SEQ "P{ PAGE \#0 }N{ SEQ "P{ PAGE \#0 }" \r1 \h } sets the value of a sequence variable that is named according to the page number it is on and the number of such fields there are on the page.

(This assumes that you are using straightforward numbering (1,2,3,4,5,etc.) you are not using chapter-page numbering (A-1,A-2 etc.) if you have more than one Word section in the document, the numbering is continuous, e.g. does not start again at 1 for each section.

If you are using A,B,C etc. rather than 1,2,3 the \# switch should return 1,2,3. But with chapter-page numbering, this would only work if the page number was unique, e.g. A-1,A-2,B-3,B-4 etc. rather than A-1, A-2, B-1, B-2 etc. )

So for example, on page 2, the first field set up in this way will set the value of the sequence variable S2N1. The second will set the value of S2N2. I refer to this series of sequence variables as “marker variables”

Above every heading row except the first, we also need a one-cell row which we will make as thin as possible (vertically) and which contains the following field codes:

{ SEQ "P{ PAGE \#0 }N{ SEQ "P{ PAGE \#0 }" }" \r{ SEQ S \c } \h }

this sets the marker variable to the section number variable S.

Finally, in the header (it can be all the headers or you can use a different first page header), you put

{ IF { SEQ "P{ PAGE \#0 }N1" \c } = 0 "{ "T{ SEQ S \c }" }" "{ "T{ SEQ "P{ PAGE }N1" \c }" }" }

What this says is

If the first marker on the page has value 0 Then 
  display the continuation text for the section that is current at the end of  
  the page
Else
  display the continuation text for the section number stored in the first marker on the page
End If

When we set a marker, we always set its value either to 1 or the current section number. So the marker value will only ever be 0 on a page which has no markers, in which case the section current at the end of the page is the same as the section current at the beginning of the page.

If the first marker on the page is set to 1, it is a start-of-section marker and there is no earlier end-of-section marker on the page. That means we have a section heading at the top of the page, so we display T1, i.e. a blank text.

Otherwise, the first marker on the page is an end-of-section marker and that means that we need to display the continuation text for the section recorded in the marker.

There is one possibility that I have not investigated in this case, and that is that the thin row containing the end-of-section marker is the first row on a page. I am not sure whether that can be avoided and it may not be easy to detect that situation, either. I think if it occurs, the only solution will be to reduce the height of the previous cell until the blank cell moves up a page.

Share:
5,307

Related videos on Youtube

superuserb49345
Author by

superuserb49345

Updated on September 18, 2022

Comments

  • superuserb49345
    superuserb49345 over 1 year

    At my workplace we make many versions of a 5-7 page document that is basically one long table in Word 2010. The repeating header row lists the type of information in each column.

    The problem is that it takes forever to do the section titles manually. My team members have to insert a new row for the Section title. Manually merge the cells into one big title cell, then manually change the side borders to white. Then if the section flows onto the next page, they have to create a new row named Section Title (Continued).

    The result of this is very visually ugly and hard to read, with the running header row appearing to float disconnected over the first section title on each page instead of sitting beneath the title as you would see in a normal table. But the worst part is that when the document is updated and the pagination changes, someone has to go back and redo all the section titles by manually adding and deleting rows.

    I feel like way too many hours have been wasted on this process and there must be a way to automate some or all of it. I am also open to using a different software than Word, if it is cheap or free for commercial use. Any suggestions are appreciated.

    • Admin
      Admin about 10 years
      Does it really have to be done as a single table? Could you use a different technique for putting the Section title at the top of every page (e.g., a { STYLEREF } field? How important are the "continuation" texts?
    • superuserb49345
      superuserb49345 about 10 years
      I have tried breaking the table up into smaller sections, but I found that although it looks nicer, it doesn't save time because I have to do both column titles and section titles manually. I have never used a style ref field or heard of it before. Thanks for the interesting idea. The continuation texts are my manager's preference, but I believe she would change her mind if there was a strong case that the difference between sections would still be visually clear.
    • Admin
      Admin about 10 years
      Can you put a sample document somewhere where it can be downloaded?
    • superuserb49345
      superuserb49345 almost 10 years
      I uploaded a sample of the table to dropbox here: dropbox.com/s/auopjeslxnuonz4/template_lorumipsum.docx As you can see, it is possible to make it so that the column titles don't automatically repeat, so that the editor would have more control over the look of each section. But then both column titles and section titles would have to be manually revised when pagination changes, thus doubling the work.
  • lowak
    lowak about 10 years
    Hm... could you provide a sample file?