The floatrow
package enables one to put in the margin captions for figures and tables, but it seems there is missing the possibility of doing the same for the lstlisting
environment from listings
package.
A workaround is to put the lstlisting
in a figure (see sample). But this doesn't allow us to keep the page breaking for long code listings. Is there a way to put lstlisting
captions in the margin? I've looked inside the floatrow
package to see if I can extend it, but I don't know how.
\documentclass{memoir}
\usepackage{listings}
\usepackage{floatrow}
\floatsetup[figure]{margins=hangright,capposition=beside,capbesideposition={top,left},floatwidth=\textwidth}
\begin{document}
\begin{figure}
\begin{lstlisting}
This is a test
\end{lstlisting}
\caption{This is a test.}
\end{figure}
\end{document}
The caption
package has a way to put Fig X:
inside the margin (see below), but putting the third argument within llap
doesn't seem to work.
\DeclareCaptionFormat{llap}{\llap{#1#2}#3\par}
\captionsetup{lstlisting}{format=llap,labelsep=quad,singlelinecheck=no}
memoir
andfloatrow
don't cooperate well. What exactly are you trying to achieve?