Written by Allen Wyatt (last updated January 6, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021
Samantha uses the STYLEREF field in the heading of my document. If the paragraph style (a heading) on the page contains a manual line break (Shift+Enter), that break also appears in the STYLEREF result in the document header. Samantha wonders if there is a way to get the STYLEREF result to not include the line break and still use the line break in the document itself.
The purpose of the STYLEREF field is to return whatever text is formatted with a particular style. For instance, if you have text on a page that is formatting using the Heading 1 style, then you can use the STYLEREF field in the page header or footer to display that text. If the text contains special characters, such as tabs or manual line breaks, then those are included in what the STYLEREF field returns—just as Samantha is seeing.
There is no way to get STYLEREF to ignore certain characters, such as the manual line break. The only thing you can do is to find a way to not include a manual line break in your text. The absolute easiest way to handle this situation is to change how you use the styles. For instance, let's say that you are using the Heading 2 style and this is what you are wanting referenced in the STYLEREF field. Instead, create two styles, such as Heading 2a and Heading 2b. Use Heading 2a for the first line of your heading and Heading 2b for the second line. In this way, your heading will not need to include a manual line break. Then, in your page header, you could use two STYLEREF fields:
{ STYLEREF "Heading 2a" } { STYLEREF "Heading 2b" }
This places the two lines of the heading right next to each other in the page header, just as you want.
If you don't want to use two styles in this manner, you can try setting tab stops and using these to remove the need to use a manual line break. For instance, in your heading style, define a tab stop at something like 0.01 inches and another just before the right margin. (As an example, for a 6.5 inch text width, you could set a tab stop at 6.49 inches.)
Now, type the first part of your heading's text, and where you would normally press Shift+Enter, instead press Tab. Since any text that you type after the tab character won't fit on the line, Word will automatically move it to the next line. So, you end up with two lines of text without the need of using Shift+Enter. You can then adjust your header style so that the tab stops don't affect the appearance of text on that line.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (9036) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
The SEQ field is a great way to insert a sequence of numbers within your document. If you want those numbers to be ...
Discover MoreCan you calculate dates using fields? Yes, but you probably don't want to except as a learning experience. An easier way ...
Discover MoreTired of getting the fields in your document overwritten by regular editing tasks? Here's how to make those mistakes more ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2024-01-06 15:57:42
To help avoid confusion I will use header and HEADING in the text below/
There are some additional details to the second approach from this tip, that may help you understand better how it works and also make it a bit easier to implement. I am taking a liberty to add them here as I contributed to this part of the tip
First let's look at the tab settings in the header. You can ***creatively*** use the right-align tab. Normally it is used to right align the text after the tab, but if that text is too long to fit in the space allotted for that tab, the text will move left to occupy only the free space, either to the end of the text before the tab, or to the left margin. Whatever doesn't fit there will extend beyond the right-align tab, kinda breaking what the tab is supposed to do, but useful in case of this tip.
You can set such tab so that it will be after the longest first line of the HEADING by at least one character. This way, putting a space and a tab instead of a manual line break in your HEADING will cause the two lines from the HEADING to display separated with a space, but as desired in one line. It will take care of varying lengths of both lines in the HEADING without having to adjust tab setting for each header. It may not handle properly cases where some of the first lines in different HEADING are very short, and others quite long, but you can play with setting more than one right-align tab stop in the header.
You can use the same trick in setting tabs in the HEADING. Instead of the first left-align tab at 0.01 inches you can set that tab to be right aligned. This will push the text against the left margin. If you used the left-align tab there, the second line of the HEADING will be offset from the margin by 0.01 inches - hardly visible but you would know it is there.
One more detail: That tab at 0.01 inches is necessary to avoid the tab character taking a line by itself. It also cannot be set at 0.00 inches. However, if using the right-align tab, you can set it a bit further from the margin (easier to do with a mouse), as long as the second line of the HEADING doesn't fit before it.
@Samantha:
If you read this please let me know (post or my e-mail is un-hidden) if you would use the second solution, or prefer the first one from the tip.
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments