Sujet : Re: label on the left side of minted or listings
De : jszhao (at) *nospam* yeah.net (Jinsong Zhao)
Groupes : comp.text.texDate : 10. Mar 2025, 17:10:48
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vqn2uh$1e9r7$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
On 2025/3/4 5:45, Peter Flynn wrote:
On 03/03/2025 04:03, Jinsong Zhao wrote:
Hi there,
>
Hi there,
>
I am typesetting code using minted or listings package. It works fine. Now I am hoping to add a label, similar to equation label, on the left side of the code block, looks like following. (%o1) is the label.
>
(%o1) code here here here
code here here
code here
code
>
However, I can't find a way to do this. Any hint will be appreciated.
I would think the simplest is to put the code listing in a list item, eg
\usepackage{enumitem,listings}
...
\begin{enumerate}[label={(\%ol)}]
\item \begin{lstlisting}
foo
bar
\end{lstlisting}
\end{enumerate}
That way (enumitem) you have good control over the label and the spacing.
Peter
Thank you very much. The code in your reply is exactly what I need. It is simple and robust (I think).
I'm just getting back to you because my last test (for some reason) didn't work, but today it did. It's really weird.
Best,
Jinsong