I simply would like to have an enumerated list that contains code, but the result is glitchy:
I would ideally have the code-block indented and starting at the same horizontal level as the item label. Here is my code:
\documentclass[10pt]{article}
\usepackage[a4paper, total={18cm, 25cm}]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{fontspec}
\usepackage{enumitem}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{multicol}
\usepackage{xpatch}
\usepackage{realboxes}
\definecolor{mygray}{rgb}{0.9,0.9,0.9}
\lstset{
language=c,
breaklines=true,
keepspaces=true,
backgroundcolor=\color{mygray},
frame=single,
framerule=0pt,
framextopmargin=3ex,
framexbottommargin=3ex,
framexleftmargin=1em,
xleftmargin={\dimexpr 1em+3pt},
linewidth={\dimexpr \linewidth-3pt}
}
\begin{document}
\begin{multicols}{2}
\begin{enumerate}[label=(\roman*)]
\item\begin{lstlisting}
#include <stdio.h>
int main() {
printf("Hello World!");
}
\end{lstlisting}
\item\begin{lstlisting}[language=lisp]
(defun make-hanoi (from-tower aux-tower to-tower)
(list from-tower aux-tower to-tower))
;; Select I'th tower of HANOI
(defun hanoi-tower (hanoi i)
(nth (1- i) hanoi))
\end{lstlisting}
\end{enumerate}
\end{multicols}
\end{document}