Listings & Code

You are encouraged to include relevant code, such as snippets or pseudocode, within the body of your disquisition. If your disquisition contains large amounts of code, we recommend placing it in a public repository and including a link in your disquisition. Alternatively, 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.

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.
  • Title font The font used in listing titles must be same type as the rest of your disquisition.
  • Margins – Listings must fit in the required 1 inch margins. Follow our recommended paragraph settings (below) to avoid listing borders spilling into margins.
  • Spacing – The line spacing scheme before and after listings should be consistent with other non-text items. See the Tables, Figures, Schemes, Etc. wiki page for help and more information. Within a listing, lines should be single-spaced with 0-12 pts of space after each line.

The following requirements differ from other non-text items.

  • Listing 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.
  • 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.
  • Portrait vs landscape orientation – Do not place listings on landscape pages.

Requirements:

If your listing is color-coded, use a contrast checker to ensure it meets this requirement.

Styles for listings are included in our Word templates under "NDSU Listing/Code", "NDSU Listing/Code Title", and "NDSU Listing/Code Note". If your document does not have these listings, download one of our templates and copy an example listing to your document; the style will also be copied into your document. (You can also use the format painter to copy formatting, using the paintbrush tool on the Home tab or hotkeys CTRL+SHIFT+C and CTRL+SHIFT+V.)

Page Content
  1. Guidelines
  2. Frequently Asked Questions
  3. Troubleshooting
    1. Border Missing
    2. Border Extends into Margin
Related Pages
  1. Digital Accessibility
  2. Tables, Figures, Schemes, Etc.
  3. Equations
  4. Appendices
  5. List of Tables, Figures, Schemes, Etc.

Quick Answers

Yes, but we strongly recommend using our NDSU Listing/Code style instead. Tables are often used to organize content, but they have additional accessibility requirements that you will need to manage and remediate in a PDF editor after converting your document. Using a table will also force you to manually adjust the borders around multi-page listings in order to meet our guidelines on listing borders.

See the issue entry below for instructions on using our styles and making listing borders.

No, sections such as the List of Algorithms, List of Listings, List of Appendix Algorithms, or List of Appendix Listings are optional sections, like a List of Equations. However, we encourage you to include them in your document, especially if these items are referenced in 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:

  • A listing should be enclosed in a border.
  • A listing should have one top and one bottom border, which appear at the beginning and end of the listing.

Resolution:

  • Apply the NDSU Listing/Code style from your document, if available.
  • Create a border around the entire listing with the border tool.

Use the "NDSU Listing/Code" style in our Word template to format the listing with a border. If you do not have this style, you can copy it into your document from our templates.

To add a border directly, select all lines in the listing then use the Border tool (Home tab -> Paragraph group) to place an outside border around the listing. You will need to adjust the left and right indentation of the listing to keep the border within the 1" page margins. If the listing continues across multiple pages, ensure there is only one top border, on the first page, and one bottom border, on the last page.

Issue: Listing Border Extends into Page Margin

Requirement:

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

Resolution:

  • Change the listing's paragraph settings to fit inside the page margins.

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.