10

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}
1
  • 1
    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
18

\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.

1
  • 5
    The *-version will insert space that doesn't disappear at page breaks.
    – egreg
    Oct 30 '11 at 23:36
11

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

2

\\ 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: \ \\.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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