Difference Between STYLEREF Field Switches \n and \r in Word
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.

- 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 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.
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.
Press Ctrl+F9 to insert empty field braces {} in your document.
Inside the braces, type the field code: STYLEREF "Heading 1" \n
Press F9 to update the field and display the full paragraph number.

Understanding the \r Switch (Relative Context)
Use the \r switch to insert the paragraph number in relative context, which adjusts based on where the field is placed in relation to the referenced heading.
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. Open WPS Writer: Launch WPS Office and open your document in WPS Writer.
- 2. Access Field Settings: Go to the 'Insert' tab, click on 'Quick Parts', and select 'Field'.
- 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. Apply and Update: Click 'OK' to insert the field. Right-click the field and select 'Update Field' to refresh the data.

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.




