Listings and Code

You are encouraged to include relevant code snippets within the body of your disquisition, but we recommend placing large amounts of code in a public repository and including a link in your disquisition. You may also place your code in one or more appendices. Listings (code blocks) should follow the same guidelines as other non-text items, with some exceptions.

Content
  1. Formatting Requirements
  2. FAQ
  3. Troubleshooting issues

Formatting Guidelines: Listings and Code

The following requirements are similar to other non-text items.

  • Numbering – Listings should labeled and numbered sequentially, like other non-text items.
  • Titles – Listings should have a title (such as “Listing 1. Python script to calculate per-beat elastance.”), like other non-text items.
  • Font The font used in listing titles must be same type as the rest of your disquisition.
  • Multiple-page listings – If a listing cannot fit on a single page, you should consider placing it in an appendix. Listings that continue over multiple pages do not need their titles repeated on each page, as the borders around the listing are sufficient to indicate its continuation.
  • Margins – Listings must fit in the required 1 inch margins. Follow our recommended paragraph settings (below) to avoid listing borders spilling into margins.
  • Spacing – Utilize a line spacing scheme before and after listings consistent with other non-text items. See the Tables, Figures, Schemes, Etc. wiki page for help and more information.

The following requirements differ from other non-text items.

  • Font The font used in listing titles and notes must be same type as the rest of your disquisition. The font used within the listing may be the same type as the rest of your disquisition, or you may use a monospaced font from our list of approved fonts: Courier New (size 10) or Computer Modern Typewriter (size 11).
  • Border – The code should be enclosed in a border, with only one top and one bottom border that appear at the beginning and end of the listing, even if it extends over multiple pages.
  • Line numbers are optional – Line numbers help readers distinguish between lines of code, especially when the code must wrap onto a new line. If you use line numbers in any listings, you must use them for all listings. You may include the line numbers within the listing border, or not, but all listings should be formatted similarly. We recommend, but do not require, including a period or colon after the line number to help separate it from the code on its line.
  • Portrait vs landscape orientation – Do not place listings on landscape pages.

Quick Answers

Yes, but it may cause as many issues as it solves. Tables may be useful tools for organizing content on your page, but they cause issues for screen readers. Using a table will also force you to manually adjust the borders around multi-page listings to conform to our guidelines.

In Word:

Use the "NDSU Listing/Code" style in our Word template to format the listing with a border. If you do not have this style, select the code in the listing and use the Border tool found on the Home tab -> Paragraph group to place an "outside border" around the listing. Additionally, you will need to adjust the left and right indentation of the listing to move the border within the 1" page margins.

No, sections such as the List of Algorithms, List of Listings, List of Appendix Algorithms, or List of Appendix Listings are optional sections, like the List of Equations. However, we encourage you to include them in your document if these items are referenced in through your chapters or appendices. Creating new lists can be done in a few simple steps.

First, copy the major heading and column headers from another prefatory list onto a new page and edit them as necessary (e.g., change the "Table" column header to "Listing"), then insert a custom Table of Contents (TOC) on that page the from the Reference tab -> Table of Contents button -> Custom Table of Contents. In the custom TOC dialog box that appears, enable the option for hyperlinks instead of page numbers, then click the Options button to open a super crusty dialog box.

In the Table of Contents Options dialog box, have only the box for Styles checked and remove the numbers from every entry. Then, place a "1" in the entry for "NDSU Listing Title". Once done, click OK, then click OK in the TOC creation dialog box to make the list. You may be asked if you want to replace your TOC--click "No". After the new list appears, this list should be formatted as any other prefatory list: apply the List of Tables/Figures/Schemes/Etc. style and manually insert a tab before the first word of each entry. (Remove bold if present.)

Issue: Border Missing or Incorrectly Formatted

Requirements:

  • The code should be enclosed in a border.
  • There should only be one top and one bottom border, which appear at the beginning and end of the listing.

Select your code and use the Border tool found on the Home tab -> Paragraph group to place a border around your listing. If the listing continues for multiple pages, there should only be one top border on the first page and one bottom border on the last page that it appears.

Issue: Listing Border Extends into Page Margin

Requirement:

  • All content in the disquisition must fit within the 1" margins of the page.
Word

When adding a border to a listing, it may extend into the page margin. Select the code in the listing and open the paragraph settings, then set the left and right indentation to move the border inside the page margins. Use the same indentation for both the left and right.