TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using minted package. My problem is \usepackage[nodisplayskipstretch]{setspace} \setstretch{1.5} line. I do need this line stretch, but I don't want it to affect code sources generated by minted. How can this be done? Also, I would like to be able to change font size used by code listings independently from rest of document. I think I want 10 or 11pts for code listings and 12pt for rest of the text.

\usepackage[nodisplayskipstretch]{setspace} \setstretch{1.5}
public class Foo
  public static void main(String[] args)
    for(int i=0; i<10; i++)
share|improve this question
up vote 11 down vote accepted

You could insert the following code in your document's preamble, after loading the minted package:


Alternatively, you could start each minted environment with the following options: baselinestretch=1 and fontsize=\footnotesize. The latter works because if you set the main font size to be 12pt, then \footnotesize will switch to a font size that's 2pt smaller; if you want your code to be typeset in 11pt (and the main font size is still 12pt), you should use the command \small instead of \footnotesize.

share|improve this answer
Or, as it was recommended in another topic, \BeforeBeginEnvironment{minted}{\begin{singlespacing*}} and \AfterEndEnvironment{minted}{\end{singlespacing*}} which may produce better spacing around the environment. – egreg Nov 21 '11 at 0:27
@egreg: Your suggestion would seem to be more in conformance with the (slighly terse) explanation given in the setspace package. I suppose which method is "better" for the OP depends largely on how much whitespace the OP would like to get above and below each minted environment. – Mico Nov 21 '11 at 0:33
@egreg I tried your solution but it seems not to work. Should I load any additional package? (do I need etoolbox?) – POliveira Apr 5 '15 at 12:55
@POliveira Yes, you need etoolbox – egreg Apr 5 '15 at 12:56
@egreg Right, I tried your solution and I was given an unknown environment error. As far as I could understand, the environment would be called singlespace instead of singlespacing. Just one more thing, are the asterisks needed at the end of the environment's name? If so, what for? Thanks – POliveira Apr 5 '15 at 14:52

A bit late to the party, but defining an environment such as


works too. Then all


will have font size set to footnotesize.

share|improve this answer

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.