Welcome to MSDN Blogs Sign in | Join | Help

The Microsoft Office Word Team's Blog

All things Microsoft Office Word, from the Word team.
BEHIND THE CURTAINS: TABLE STYLES

Table Styles are my favorite type of Style in Word. They allow you to quickly and consistently format the table itself (e.g. borders, shading, etc.), the content within the table (E.g. line spacing, font color, font size, etc.), and they can also can tell a table when to do these (e.g. shade every other row, bold text in the first column, etc.). The first two enable you to create really rich tables, and the last one (which I'll call Conditional Formatting for the rest of this post) enables you to easily work with those rich tables. Both are quite important.

Before we can get into all that, you need to know a bit about how Word thinks about tables…

The Structure of Tables

Word understands all of the following as discrete actionable parts of a table:

  • Whole Table
  • Header Row
  • Total Row
  • First Column
  • Last Column
  • Odd Banded Rows
  • Even Banded Rows
  • Odd Banded Columns
  • Even Banded Columns
  • Top Left Cell
  • Top Right Cell
  • Bottom Left Cell
  • Bottom Right Cell

 

This is cool because it allows Table Styles to specify a conditional behavior for each of these parts. For example, in the table below, the Header Row and Total Row have top and bottom blue borders and are bolded, the Odd Banded Rows have blue shading, and the First Column and Last Colum are bolded.

And it is important to note that this is not the same as saying:

  • The row with "College," "New students," "Graduating students," and "Change," as well as the row with "Total," "998," "908," and "90" should have top and bottom blue borders and should be bolded
  • The 1st, 3rd, 5th, 7th, 9th, and 11th rows below the "College" row should have blue shading in them
  • The column containing "Cedar University," "Elm College," etc., and the column containing "+7," "+9," etc., should be bolded

The former is formatting applied based on a table structural condition being true…i.e. Conditional Formatting. The latter is formatting directly applied to parts of the table. This makes a big difference when you start adding and subtracting rows and columns.

Why Conditional Formatting Based on a Rich Table Structure is Useful

Let's consider a simpler example using two tables—X and Y—where X uses a Table Style and Conditional Formatting and Y uses direct formatting.

Table X

Table Style + Conditional Formatting on the Header Row, First Column, Total Row, and Odd Banded Rows

Table X

Two rows added under "Monday," "Wednesday," "Friday"

Table Y

Direct formatting

Table Y

Two rows added under "Monday," "Wednesday," "Friday"

As Table X grew, the formatting specified by the Table Style adjusted conditionally based on the new structure of the table. As Table Y grew, the new rows were directly formatted just like the row next to them. Smiley for the former, frowny for the later.

Exercise: The first table shown in this post—the one with the colleges—uses a Table Style with Conditional Formatting. How would that table look if you added a row to top and bottom, and a column to the left and right side? See the end of this post for the answer.

Conditional Formatting's Order of Operations

Hopefully the previous example shows you why the Conditional Formatting aspect of Table Styles is so important. After all, what good is a rich table if you have to do a bunch of work every time you add a row or column?

That being said, the next question that comes to mind is around order of operations. Specifically, what is the order in which Conditional Formatting is applied in tables? I.e. In the previous example, how did Table X know that the Conditional Formatting for the First Column and Header Row should be applied "over" the shading on the Odd Banded Rows? Put yet another way, how did Word know not to make Table X look like this:

The answer is that Word shows Conditional Formatting on "smaller" parts over Conditional Formatting on "bigger" parts. We do this because otherwise you wouldn't see the Conditional Formatting on the smaller parts. If we don't show the Header Row (smaller) over the Odd Banded Rows (larger), then you don't see the Header Row (e.g. funky table immediately above). If we do show the Header Row (smaller) over the Odd Banded Rows (larger), then you see both the Header Row and the Odd Banded Rows (e.g. Table X).

With that, here's the order that Word applies Conditional Formatting:

  1. Whole Table
  2. Column Banding
  3. Row Banding
  4. Header Row, Total Row
  5. First Column, Last Column
  6. Top Left Cell, Top Right Cell, Bottom Left Cell, Bottom Right Cell

    Note: Conditional Formatting on the four corners is only applied if the respective rows and columns also use Conditional Formatting. E.g. Top Left Cell Conditional Formatting is only applied if First Column and Header Row are conditionally formatted.

We go from big to small and conditionally format the whole table, then band the columns, move on to band the rows, gussy-up the header row and total row, take care of the first and then last column, and finish-up in the four corners.

If you want to get your hands dirty and create your very own Table Style, simply insert a new table, drop the Table Styles Gallery, and click New Table Style at the bottom of the Gallery.

Note: If you really want to flex your Table Style muscles, you can specify the number of rows or columns in a "band." E.g. Instead of having one row per band like the tables in this post, you can specify that there should be two rows per band by dropping the Table Styles Gallery, clicking Modify Table Style, click the Format button, and click Banding.

Summary

While you may not now have the same undying love for Table Styles that I have, you hopefully now know that:

  • In addition to formatting the table and the contents of the table, Table Styles also define the conditions for when to apply that formatting.
  • This is possible because Word sees tables a collection of parts that can each be acted upon conditionally.
  • This is useful because it makes editing rich tables much easier.
  • Smaller parts of tables are formatted over top of larger parts of tables.

- Jonathan Bailor

Answer to Exercise

Posted: Monday, November 24, 2008 11:34 AM by wrdblog

Comments

Eric said:

I agree that table styles are pretty cool, but one thing really bugs me: there's no way I can find to specify that an inline table (no text wrapping) should always have a certain amount of vertical space after it, before the next paragraph's text begins. Paragraph styles let you set before and after "spacing." Why not table styles? I've only been able to achieve this by adding blank paragraphs (which is poor document design) or enabling text wrapping, which doesn't really work well for the kinds of inline tables I'm talking about.

# December 13, 2008 11:38 AM

Pam Caswell said:

Table styles are great, but they do not handle  multirow headings well.  If I specify a bottom border for the heading row, Word adds that border to  every row within the heading rows or, when a cell is split into two rows, to the upper cell or row of the heading rows.  I can specify the line weights and colors for internal lines in the heading rows, but I have to apply them manually.

I very much agree about the before and after spacing on tables.  I use an empty, 7 point "total" row with no borders except at the top to get this spacing. But I think being able to specify the spacing as you can with wrapped tables would be better.  

PamC

# December 18, 2008 1:04 PM
New Comments to this post are disabled
Page view tracker