3

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.
1
  • 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? Commented Aug 28, 2012 at 0:37

1 Answer 1

6

\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 ...
    
1
  • 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
    Commented Aug 28, 2012 at 6:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .