Document Editing Problems

Difference Between STYLEREF Field Switches \n and \r in Word

Anum MushtaqAnum Mushtaq Oct 29, 2026 868 views

Question details

The user wants to understand the functional differences between the \n and \r switches when using the STYLEREF field code to reference headings and paragraph numbers.

Difference Between STYLEREF Field Switches \n and \r
Product
Word Processing Software
Device & OS
not provided
Scenario
Using advanced field codes for document formatting, specifically inserting cross-references or headers/footers linked to styled paragraphs.
Observed behavior
Need clarification on how \n (paragraph-numbering context) and \r (relative context) behave differently when inserted in a document.
Before you start

Before working with field codes, ensure paragraph numbering and heading styles are properly applied throughout your document, as the STYLEREF field relies on these existing styles to function correctly.

Solution 1Recommended

Understanding the \n Switch (Paragraph Numbering Context)

Use the \n switch when you want the STYLEREF field to display only the full paragraph number of the referenced style without the text.

The \n switch is designed to extract the paragraph number of the styled text. It ignores the actual text content of the heading or paragraph and outputs only the complete numbering sequence, regardless of where the field is placed in the document.

1
Insert the Field

Press Ctrl+F9 to insert empty field braces {} in your document.

2
Type the Code

Inside the braces, type the field code: STYLEREF "Heading 1" \n

3
Update the Field

Press F9 to update the field and display the full paragraph number.

Understanding the \n Switch (Paragraph Numbering Context)
Full Context: The \n switch always provides the full context of the number (e.g., '1.2.3'), making it ideal for absolute references.
Advanced Document Formatting

Master Field Codes with WPS Writer

WPS Writer fully supports advanced field codes, including STYLEREF, allowing you to create dynamic headers, footers, and cross-references with ease. It is highly compatible with Microsoft Word documents.

  1. 1. Open WPS Writer: Launch WPS Office and open your document in WPS Writer.
  2. 2. Access Field Settings: Go to the 'Insert' tab, click on 'Quick Parts', and select 'Field'.
  3. 3. Insert STYLEREF: Choose 'StyleRef' from the field names list, select your desired style, and check the options for inserting paragraph numbers (equivalent to \n or \r).
  4. 4. Apply and Update: Click 'OK' to insert the field. Right-click the field and select 'Update Field' to refresh the data.
Full support for STYLEREF and other advanced field codesSeamless compatibility with Microsoft Word (.docx) formatsIntuitive interface for managing heading styles and paragraph numberingFree and lightweight alternative for professional document editing
QA img-9

Frequently Asked Questions

Can I use both \n and \r switches together in a STYLEREF field?

No, the \n and \r switches serve different purposes for numbering context and generally should not be combined. Choose \n for the full paragraph number or \r for a relative context number.

Why is my STYLEREF field showing an error instead of the paragraph number?

This usually happens if the style referenced in the field code (e.g., 'Heading 1') does not exist in the document, or if the style has no paragraph numbering applied to it.

How do I view the field codes instead of the results?

You can toggle between viewing field codes and their results by pressing Alt+F9 on your keyboard. This allows you to edit the STYLEREF switches directly.

Does the STYLEREF field update automatically?

STYLEREF fields in headers and footers usually update automatically when printing or previewing. For fields in the main body, you may need to select the text and press F9 to force an update.