404 Tech Support

Creating a style in Word 2013 for code snippets

In the midst of writing a paper this weekend, I needed to include some segments of code in the paper. Word is good at formatting text to follow the standard paragraph format but it could use a little help when it comes to displaying code. So, I set out to create a style just for code which would give it a nice little box, stop it from being spellchecked, and preserve the formatting.

To start with, I copied my code from Notepad++. Under the Plugins menu and NppExport, there is a function called ‘Copy HTML to Clipboard’ which works very well to preserve the formatting.

I pasted that into Word 2013 and immediately received some red squiggles under variable names and function calls. I then highlighted the code in Word and clicked the drop-down arrow (down arrow with a horizontal line over it in the bottom-right corner) on the Home tab in the Styles section. From the menu that expanded, I chose Create a Style.

A new window popped up with the title “Create New Style from Formatting”. I named the style Code and hit the Modify button to make some tweaks to it. This brought up another window with many options to it.

In the bottom-left corner is a Format button, providing access to a lot more settings that can be tweaked for the style. I started by fixing the spell-checking within the code snippet by selecting Language.

Inside the Language settings, I checked the box “Do not check spelling or grammar”.

From there, I returned to the Modify window and chose the Format drop-down again. This time, I went to Border and selected Box for the Setting.

I didn’t quite like the spacing, so under the Modify window I chose Format and went to Paragraph this time. I increased the spacing after and checked the box to “Don’t add space between paragraphs of the same style” so there wouldn’t be spacing inside the code snippet but this gave a more comfortable gap between the code box and the next normal paragraph.

Finally, I hit ok to see the new Code style applied to the selected text and I liked the look.