Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using minted for the first time and after reading the docs, I could not find a way to put a label in the code listing. Just to be clear, I am not speaking of the \label of a listing environment. I am trying to reproduce a listing like

  label={This is the label},numbers=left]
  int main() { return 0; }

which creates a nice frame with a label "This is the label" in the middle.

Since minted uses fancyvrb, I though it would be easy to do it, but I did not succeed. The closer approach so far is

 int main() { return 0; }

Does anyone know a way or a hack to achieve this?

share|improve this question
For the record, this wasn’t included “on purpose” – I didn’t think it was really all that useful, considering that you can provide float captions, and the name “label” clashes with a distinct concept in TeX (i.e. references) which I find awkward. Anyway, I’ve now added the option (but heaven only knows when I’ll find time to push the next release). – Konrad Rudolph Jan 4 '11 at 20:49
@Konrad: how should there be a confict? And it is useful when all those verbatim listings are not of a float type. And if you have a problem then call it title, which doesn't really make a difference. And why do you not pass all options simply to fancyvrb, then you do not have to define them in the package? – Herbert Jan 5 '11 at 13:17
@Herbert: there’s a conflict of meanings when talking about this (e.g. in the documentation: it’s not enough to say that “this option adds a label” since that would be confusing). – Konrad Rudolph Jan 5 '11 at 13:20
@Konrad: understood, then call it a title – Herbert Jan 5 '11 at 13:24
@Konrad: why not: "All available optional arguments of fancyvrb are possible". Then you do not have to say anything about a label or title or ... – Herbert Jan 5 '11 at 13:26

2 Answers 2

up vote 11 down vote accepted

I suppose, it is only missing in minted.sty


int main() { return 0; }
int foo() {return 1; }

alt text

share|improve this answer
(+1) Huh, that's really more elegant! – chl Jan 4 '11 at 19:30
Excellent solution – YuppieNetworking Jan 5 '11 at 13:14

I didn't see anything about that in the reference manual. However, I do think you can get a pretty output with tikz. Here is an example,

% that should go into your preamble
% -%<------------------------------


                   text width=0.85\textwidth,rectangle,
                   rounded corners=0pt,inner sep=0pt,inner ysep=10pt]
% ------------------------------>%-

% and here is a framed snippet
      int main() { return 0; }
\node[title] at (box.north) {Useless function};

The output is shown below:

alt text

share|improve this answer
Thanks chl (+1), that's a nice solution. I only have one problem: sometimes the code that I want to show is longer than a page. Normally fancyvrb and minted handle this gracefully by cutting it (when not using a float). However, with tikzpicture I imagine that it becomes a float and hence, it is not breakable in two pages. This is a supposition, of course, since I have never used tikz before. – YuppieNetworking Jan 4 '11 at 15:56
I used such construction for very short snippet of code, or text advertising. Actually, @Herbert's solution looks better! – chl Jan 4 '11 at 19:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.