Take the 2-minute tour ×
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.

I am not very familiar with all latex details, but I'd like to use the listings package in a tufte-book document. However, the listings package places its captions above or below the listing and I couldn't find a way to adjust that in a way so that the caption is put to the page margin as with tufte-book's \marginnote etc.

Any idea how to solve that?

share|improve this question
    
i found a way with that tipp thank you –  Peter Sommerlad Mar 6 '12 at 16:21
    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Mar 1 at 18:59
add comment

2 Answers

It is best neither to mess with the listings or the tufte-book commands, as they are both difficult to modify. I would simply load the listing in a \begin{figure}...\end{figure} environment. If you want to have a different float for listings, you can use the float package.

\documentclass{tufte-book}
\usepackage{listings}
\begin{document}
\begin{figure}
\begin{lstlisting}
This is a test
\end{lstlisting}
\caption{This is a test.}
\end{figure}
\end{document}
share|improve this answer
add comment

Thanks to the above answer, this is what I use now:

\newcommand{\cpplistinc}[1]{
    \renewcommand{\figurename}{Listing}
    \begin{figure}
    \lstinputlisting[style=C++11,caption={}]{../src/ch\thechapter/#1}
    \caption{#1}
    \label{ch\thechapter/#1}
    \index{#1 in chapter \thechapter } % might use a separate index for that.
    \end{figure}
    \renewcommand{\figurename}{Figure}
    }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.