1

I am trying to put my lstlisting on the same page as the Chapter title. Since the chapter is in my appendix I do not have any other content exept the lstlisting. Currently, the lstlisting is going on the next page and the page with the chapter is empty. Is there a solution to this?

This is my code:

\chapter{ARFF dataset file sample}

\begin{lstlisting}[caption=WEKA ARFF file extract,
label=weka-arff-code,
captionpos=b,
frame=single,
basicstyle=\fontsize{9}{11}\selectfont,
float,
floatplacement=H,
breaklines=true]
@relation HAR

@attribute accX__fft1 numeric
@attribute accX__fft2 numeric
@attribute accX__fft3 numeric
@attribute accX__fft4 numeric
@attribute accX__fft5 numeric
@attribute accY__fft1 numeric
@attribute accY__fft2 numeric
@attribute accY__fft3 numeric
@attribute accY__fft4 numeric
@attribute accY__fft5 numeric
@attribute accZ__fft1 numeric
@attribute accZ__fft2 numeric
@attribute accZ__fft3 numeric
@attribute accZ__fft4 numeric
@attribute accZ__fft5 numeric
@attribute accM__fft1 numeric
@attribute accM__fft2 numeric
@attribute accM__fft3 numeric
@attribute accM__fft4 numeric
@attribute accM__fft5 numeric
@attribute class {walking,running,static,cycling}

@data
9,-76,-834,25,22,4,-1,-401,-190,-3,3,5,-213,-94,-45,2,-50,-49,-15,18,walking
-0,-184,140,4,-34,-2,13,45,63,-8,0,51,-68,-30,-72,1,-52,15,-51,63,walking
-1,-13,-30,3,2,3,-18,-2,3,-21,-1,2,-4,-9,-1,-2,33,3,16,20,walking
0,-16,-17,-22,6,-3,-6,-8,-16,-3,-15,-2,12,-5,9,8,8,37,38,-18,walking
-6,-22,14,-54,1,14,8,27,9,60,-22,-31,-11,-11,4,-7,1,0,-3,-39,running
-3,-11,-35,-3,-53,-13,-45,23,-57,17,-2,52,13,58,15,22,48,-36,25,-50,running
3,7,-11,27,-41,-19,-31,-53,-107,10,0,-42,22,-42,3,20,34,-26,76,-104,running
-3,37,34,9,58,0,30,97,-74,83,4,-13,-39,40,26,-4,15,-10,27,-26,cycling
-1,-91,-131,-121,-58,-4,6,-66,22,70,3,-30,-76,-63,-30,-1,-39,-10,-39,-76,cycling
1,-54,-41,-180,114,-3,4,-21,78,-188,3,8,-56,-19,70,0,-38,22,-83,103,cycling
0.3,0,-1,1,-1.4,0,1,-1,0,0,0,-1,0,0,0,0,0,0,0,0,static
0,-6,48,-8,0,0,-6,-21,2,5,0,-1,42,-6,0,0,0,-1.5,0,-1.6,static
-0.3,8,-4,3,-4,0.1,6,-4,2,-3,0,2,-2,2,-1,0,0.2,1,-0.4,0.2,static
\end{lstlisting}

and the result: enter image description here

2
  • 1
    Does removing the float statement in the lstlisting options help?
    – user31729
    Commented Mar 19, 2017 at 11:10
  • @ChristianHupfer It was that simple! Thank you so much! If you want you can put your comment in an answer so I can accept it :) Commented Mar 19, 2017 at 11:16

1 Answer 1

2

Since float and floatplacement options have been used in the lstlisting environment, the listing is caused to float away to a position where LaTeX thinks it would be placed best, especially if the size of the float is too large to fit on a chapter opening page.

Just remove the float specification, i.e. the listing will start right at the position it is specified in the document (if there's enough space)

You must log in to answer this question.

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