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.

Is there any way for me to insert a linebreak after a \lstinputlisting? At the moment text proceeding the code in the lstinputlisting follows directly after but I'd prefer to have a linebreak but can't seem to put it in.

This is what it looks like:

With this code:

\lstinputlisting{newtonsMethod.m}

The derivative function implements the central difference method. The simple implementation is shown below.

This doesn't compile if I put \\ after the \lstinputlisting.

I can't answer my own question cause I'm too new to the site but I managed to figure it out:

Got what I was after by putting \ after the lstinputlisting, like so.

\lstinputlisting{newtonsMethod.m}\

The derivative function implements the central difference method. The simple implementation is shown below.
share|improve this question
    
What do you mean with "a linebreak"? Do you want to increase the vertical space between the bottom of the listing and the first line of the following text? –  Gonzalo Medina Aug 28 '12 at 0:37
add comment

1 Answer

\lstinputlisting automatically ends the paragraph at the end. It seems like you're after a bigger skip below this, which you can do in multiple ways:

  1. Insert a vertical skip (something like \smallskip, \medskip or \bigskip):

    \lstinputlisting{newtonMethod.m}
    \bigskip
    The derivative function ...
    
  2. Insert vertical space using \vspace{<len>} where <len> is any TeX length:

    \lstinputlisting{newtonMethod.m}
    \vspace{\baselineskip}
    The derivative function ...
    
  3. Use the key belowskip (default set to \medskipamount):

    \lstinputlisting[belowskip=40pt]{newtonMethod.m}
    The derivarive function ...
    
share|improve this answer
    
Method 3 should is built into the listings package and, thus, should be considered as the recommended way. By putting something like \lstset{belowskip=2ex} into the preamble, the spacing below all listings can easily be defined (and changed) consistently. –  Daniel Aug 28 '12 at 6:21
add comment

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.