Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add code snippets in Microsoft Word

Tags:

ms-word

I am trying to add code snippets in Microsoft Word for my final thesis. The image below is the sample. I want to ask how to add these kind of code snippets in a word document.

enter image description

like image 285
Zohaib Ahmad Avatar asked May 03 '17 19:05

Zohaib Ahmad


2 Answers

I found the following here.

Here is the best way, for me, to add code inside word:

  1. go to "insert" tab, click "object" button (it's on the right)
  2. choose "OpenDocument Text" which will open a new embedded word document
  3. copy and paste your code from Visual Studio / Eclipse inside this embedded word page
  4. save and close

The result looks very nice. Here are the advantages of this method:

  • the code keeps its original layout and colors
  • the code is separated from the rest of the document, as if it was a picture or a chart
  • spelling errors won't be highlighted in the code (this is cool !) And it takes only few seconds.
like image 181
f_qi Avatar answered Sep 27 '22 19:09

f_qi


If you are simply looking to format text like your example apply the Block Text paragraph style. You may need to modify the style to add the background colour you want. Whilst modifying the style you can also tell Word not to check spelling or grammar for all instances of that style as shown below.

Modify Style Language dialog

like image 21
Timothy Rylatt Avatar answered Sep 27 '22 17:09

Timothy Rylatt