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.
I found the following here.
Here is the best way, for me, to add code inside word:
- go to "insert" tab, click "object" button (it's on the right)
- choose "OpenDocument Text" which will open a new embedded word document
- copy and paste your code from Visual Studio / Eclipse inside this embedded word page
- 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With