Take the 2-minute tour ×
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'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}
\begin{lstlisting}
    % My code
\end{lstlisting}

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

\lstset{language=Java, caption=ClassB.java}
\begin{lstlisting}
    % My code
\end{lstlisting}
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

3 Answers 3

up vote 10 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
3  
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

Your Answer

 
discard

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.