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.

When using lstlisting, my displayed code is sent back on the top of my page. I would like to have the same kind of option as:

\begin{figure}[h]
...
\end{figure}

ie having displayed my code exactly where I put it in my latex code.

My current code for lstlisting is as follow:

\begin{lstlisting}[float,style=Bash,caption={toto.bash},label=lst:logging]
...
\end{lstlisting}

Thanks!

Second question: How to display lstlisting on 2 followed pages, when the code is too long?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Don't use figure environment. Generally you don't need to use figure as listings provides a float option by itself. But for your case, you shouldn't use that either (as you do not want floating). The following code works as you wanted:

\documentclass{article}
\usepackage{listings}
\usepackage{lipsum}
\begin{document}
\lipsum[1-4]
\begin{lstlisting}[caption=Listing,language=c,escapechar=+] %% don't use float option here
+{public void}+ Method () {
  try {
    .. Original code
    .. After returning
  }
  catch (...) {
    .. After throwing
  }
  finally {
    .. After
  }
}
\end{lstlisting}
\end{document}

enter image description here

As you can see, the code runs in to second page as well.

share|improve this answer
    
You were right! It comes from the float. Thank you for your help, fast and helpful. Have a nice day! –  user23710 Jan 6 '13 at 10:54
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.