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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Force figure placement in text
How to influence the position of float environments like figure and table in LaTeX?

How can I force LaTeX to insert a figure exactly where I want.

Here's the code I use:

\lstset{framexleftmargin=0mm, frame=shadowbox, rulesepcolor=\color{black},basicstyle=\ttfamily\small,breaklines,
\begin{figure} [htbp!]
root@bt:~# nmap -O www.we****t***.com

Starting Nmap 6.01 ( http://nmap.org ) at 2012-12-21 15:38 CET
Nmap scan report for www.we****t***.com (217.6*.***.**)
Host is up (0.0087s latency).
Not shown: 990 filtered ports
21/tcp   open   ftp
22/tcp   open   ssh
53/tcp   open   domain
80/tcp   open   http
110/tcp  open   pop3
143/tcp  open   imap
443/tcp  open   https
587/tcp  closed submission
3306/tcp open   mysql
Device type: general purpose
Running (JUST GUESSING): Linux 2.6.x (90%)

Aggressive OS guesses: Linux 2.6.22 (90%),
OpenWrt Kamikaze 7.09 (Linux 2.6.27) (89%),
Linux 2.6.18 - 2.6.24 (89%),
Linux 2.6.23 (86%)

No exact OS matches for host (test conditions non-ideal).

OS detection performed.
Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 79.16 seconds
\caption{Nmap -O}

LaTeX places the figure on another page which is astonishing since it makes the whole work ugly.

Here's the preamble I use:

%\usepackage {listingsutf8}

\usepackage{amsmath}% http://ctan.org/pkg/amsmath


\titolo{...Injection ...
\relatore{Chiar.mo xxxx}


\dedica{Ai miei genitori}



Vorrei ringraziare ...

share|improve this question

marked as duplicate by yo', Martin Schröder, Kurt, Werner, lockstep Jan 2 '13 at 0:08

This question was marked as an exact duplicate of an existing question.

Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Benedikt Bauer Jan 1 '13 at 22:54
Could Frank Mittelbach's answer to this question be of any help? – Marc van Dongen Jan 1 '13 at 22:56
You should use the inherent structure provided by listings, which allows you to say \begin{lstlisting}[...,float=H,caption={..}]. For this you would also need the float package. – Werner Jan 1 '13 at 22:56
See also Force figure placement in text (duplicate, perhaps) – Torbjørn T. Jan 1 '13 at 23:03
Not exactly, read Werner's comment, and/or search the listings documentation for the word "caption". – Torbjørn T. Jan 1 '13 at 23:15