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 trying to create a LaTeX document with several blocks of source code included. Between these blocks of code I want to add in a few lines of whitespace. I have tried using \\ however this didn't work.

Here is what I have at the moment...

\lstset{language=Java, caption=ClassA.java}
    % My code

\\ % This is where I want to make some whitespace

\lstset{language=Java, caption=ClassB.java}
    % My code
share|improve this question

migrated from stackoverflow.com Oct 30 '11 at 23:30

This question came from our site for professional and enthusiast programmers.

Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. – Werner Oct 30 '11 at 23:36
up vote 14 down vote accepted

\vspace{2cm} is usually good for these sorts of things; it will insert 2cm of vertical space. In certain situations (I forget exactly when) you need to use the starred version, \vspace*{2cm}. Obviously, adjust the length as necessary.

share|improve this answer
The *-version will insert space that doesn't disappear at page breaks. – egreg Oct 30 '11 at 23:36

Try either \smallskip, \medskip or \bigskip. Or use \vspace.

share|improve this answer

\\ ends a line. If there is no line preceding it, you cannot end it either.

A simple hack for this (in situations where you cannot use \vspace, is to print one space character and then the new line: \ \\.

share|improve this answer

If you have an line Ending \\ you can type the wanted distance in brackets.

So \\[4cm] will produce a whitespace of 4 cm.

At the beginning of a section \vspace* is a better solution. You can only use a line ending there by putting something in front (like ~\\) but this will probably cause an underfull hbox warning.

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.