I have been looking everywhere and I found the ways of doing this with images with \usepackage{float}
for \includegraphics
. But I also have texts from .txt
files that I have as in \lstinputlisting
that I would also like to force.
I don't really understand the documentation of how placement works.
5.1 Space and placement
float=[*] <subset of tbphi> or
float
floatplacement
makes sense on individual displayed listings only and
lets them float. The argument controls where LATEX is allowed to put
the float: at the top or bottom of the current/next page, on a
separate page, or here where the listing is. The optional star can be
used to get a double-column float in a two-column documentfloatplacement=<place specifiers> tbp
is used as place specifier if
float is used without value.
Any ideas how I force the code below with \lstinputlisting
?
\lstinputlisting[float=h,frame=tb,
caption=Iteration: 2. Variable importance for unpruned decision tree ,captionpos=b, belowcaptionskip=2cm ,label=zebra]{results/maybe_80_20.txt}
Best Answer
Package
listings
supports captions for not floating listings. See the initial paragraph in section 5.7, "Captions" in thelistings
manual:So you can simple remove the
float
option from your example and use, e.g.:to get
You have to use option
float
only for those listings, that should float.Note:
listings
also allows page breaks inside non-floating listings with captions! So you have to use either a\parbox
orminipage
around them, if page breaks should not be allowed:results in:
while
results in:
BTW: Option
H
of packagefloat
cannot be used with\lstinputlisting
:would result
As you can see, the listing is missing (without any error message). So: Don't do this!