4

The following code produces strange results. Everything looks fine, if I don't include the subfig package or don't use the xleftmargin parameter. It also works if I use captionpos=t. Is there a workaround for this problem? I have to use subfig, xleftmargin and captionpos=b. I am using TexLive 2013 with all updates installed.

\documentclass{article}
\usepackage[english]{babel}

\usepackage{subfig}
\usepackage{blindtext}
\usepackage{listings}

\lstset{
   breaklines=true,
   captionpos=b,
   numbers=left,
   xleftmargin=20em
}

\begin{document}

\begin{lstlisting}[caption={information information information information information information information}]
A = B
C = D
\end{lstlisting}
\blindtext

\end{document}

Result:

enter image description here

jub0bs
  • 58,916

1 Answers1

3

If you just need subfig but don't need the features from the caption package, which is the real responsible of this behaviour, load subfig with the caption=false option as in

\usepackage[caption=false]{subfig}

A complete example with your code in which I've also included the change in \pretolerance suggested by Herbert in his answer to Hyphenation in listings captions doesn't work correctly:

\documentclass{article}
\usepackage[english]{babel}
\usepackage[caption=false]{subfig}
\usepackage{listings}
\usepackage{blindtext}

\lstset{
   breaklines=true,
   captionpos=b,
   numbers=left,
   xleftmargin=20em
}

\begin{document}

\begin{lstlisting}[caption={\pretolerance=100 information information information information information information information}]
A = B
C = D
\end{lstlisting}
\blindtext

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • Thanks for your help but in my real document I also need the caption package which distorted the caption again. Is there a solution for this? I have tried to change the include order but no success... :( – user3389757 Apr 28 '14 at 21:12