Field codes: StyleRef field

The StyleRef field inserts text that's formatted with the specified style (style: A combination of formatting characteristics, such as font, font size, and indentation, that you name and store as a set. When you apply a style, all of the formatting instructions in that style are applied at one time.). When inserted in a header or footer (header and footer: A header, which can consist of text or graphics, appears at the top of every page in a section. A footer appears at the bottom of every page. Headers and footers often contain page numbers, chapter titles, dates, and author names.), the StyleRef field prints the first or last text formatted with the specified style in the document body of the current page, allowing you to print dictionary-style headers or footers.

Syntax

When you view the StyleRef field in your document, the syntax looks like this:

{ STYLEREF StyleIdentifier [Switches ] }

 Note    A field code tells the field what to show. Field results are what’s shown in the document after having evaluated the field code. To toggle between viewing the field code and the field code results, press Alt+F9.

Instructions

StyleIdentifier

Name of the style used to format the text you want to insert. The style can be a paragraph style (paragraph style: A combination of character- and paragraph-formatting characteristics that are named and stored as a set. You can select a paragraph and use the style to apply all of the formatting characteristics to the paragraph at one time.) or a character style (character style: A combination of any of the character formatting options identified by a style name.). If the style name contains spaces, enclose it in quotation marks.

Switches

\l

Inserts the last text formatted with the style on the current page instead of the first text formatted with this style. Microsoft Word searches the page for the style from bottom to top instead of from top to bottom (the default).

\n

Causes the field to display the entire paragraph number for a referenced paragraph without trailing periods. No information about prior levels is displayed unless it is included as part of the current level.

\p

Causes the field to display its position relative to the source bookmark (bookmark: A location or selection of text in a file that you name for reference purposes. Bookmarks identify a location within your file that you can later refer or link to.) using the word "above" or "below."

If the StyleRef field appears in the document before the bookmark, it evaluates to "below."

If the StyleRef field appears after the bookmark, it evaluates to "above."

If the StyleRef field appears within the bookmark, an error is returned.

\r

Inserts the entire paragraph number of the bookmarked paragraph in relative context — or relative to the paragraph numbering scheme — without trailing periods.

\t

When used with the \n, \r, or \w switch, causes the StyleRef field to suppress nondelimiter, or nonnumerical, text.

With this switch, for example, you can reference "Section 1.01," and only "1.01" is displayed in the result.

\w

Inserts the paragraph number of the bookmarked paragraph in full context, from anywhere in the document.

For example, when referencing paragraph "ii.," a StyleRef field with the \w switch would return "1.a.ii" as a result.

Examples

If inserted in a header, the following field displays the contents of the first paragraph formatted with the style "Heading 3" on the current page.

Field:

On this page: { STYLEREF "Heading 3" }

Result:

On this page: Summary of Sales by Region

To print the first and last names that appear on each page in the membership directory for your organization, first apply a character style (character style: A combination of any of the character formatting options identified by a style name.) to each member's last name. Then insert StyleRef fields in the header. The second StyleRef field includes the \l switch, which inserts the last name on the page.

Field:

{ STYLEREF "Last Name" } — { STYLEREF "Last Name" \l }

Result:

Ackerman — Berg

StyleRef field location

Where you insert the StyleRef field determines the direction that Word searches for the style and thus can affect which text is inserted.

When you insert the field in:

  • Document text: Word searches backward from the StyleRef field for the specified style. If the style isn't found, Word searches forward from the StyleRef field.
  • Footnotes, annotations, and endnotes: Word searches backward from the footnote, annotation, or endnote reference mark for the specified style. If the style isn't found, Word searches forward from the reference mark.
  • Headers and footers (results for printed document): Word searches the current page, from top to bottom, for the specified style. If the style isn't found, Word searches next from the top of the page to the beginning of the document, and then from the bottom of the page to the end of the document. If the \l switch is used, Word searches from the bottom of the page to the beginning and then to the end of the document.
 
 
Applies to:
Word 2013, Word 2010, Word 2007, Word 2003