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.
\documentclass{mwrep}
\usepackage{minted}
\usepackage{lipsum}

% question regarding this code
\setlength{\belowcaptionskip}{-10pt}
% end

\begin{document}
\lipsum[1]
\begin{listing}[h]
\begin{verbatim}
1
2
3
4
\end{verbatim}
\caption{test}
\label{lst}
\end{listing}
\lipsum[2]
\begin{figure}[h]
\begin{verbatim}
1
2
3
4
\end{verbatim}
\caption{test}
\label{ver}
\end{figure}
\lipsum[3]
\end{document}

Why does \listing ignore change of \belowcaptionskip? What can I change to make listing affected by it as in case of figure?
How can I make caption of listing be identical with caption of figure in every manner (like fontsize, which on my example is smaller in figure).

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

The mwrep document class redefines the way \caption behaves for standard floats (i.e., table and figure); the minted package defines its listing environment using the features provided by the float package; as a result, the redefinition of mwrep doesn't apply to the listings environment; one way to solve the problem is to \restyle the listing float to use the settings that mwrep uses (in particular, \captionsettings); here's such an example illustrating this approach with a modified version of the plain float style as defined by the float package:

\documentclass{mwrep}
\usepackage{minted}
\usepackage{lipsum}

\setlength{\belowcaptionskip}{-10pt}

\makeatletter
\renewcommand\floatc@plain[2]{\setbox\@tempboxa\hbox{\captionsettings{\@fs@cfont #1:} #2}%
  \ifdim\wd\@tempboxa>\hsize \captionsettings{\@fs@cfont #1:} #2\par
    \else\hbox to\hsize{\hfil\box\@tempboxa\hfil}\fi\vskip\belowcaptionskip}
\makeatother

\floatstyle{plain}
\restylefloat{listing}

\begin{document}
\lipsum[1]
\begin{listing}[h]
\begin{verbatim}
1
2
3
4
\end{verbatim}
\caption{test}
\label{lst}
\end{listing}
\lipsum[2]
\begin{figure}[h]
\begin{verbatim}
1
2
3
4
\end{verbatim}
\caption{test}
\label{ver}
\end{figure}
\lipsum[3]
\end{document}

enter image description here

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.