24.5.12

Change \abovecaptionskip for some floats only

I'd like to change the \abovecaptionskip (space between figure and caption) for the listing floats of the minted package only.


Use package caption and its \captionsetup. For listing it must be inside a group to hold it local or alternetively use the new environment mylisting. For a default figureenvironment it can be inside and is then local by default.







\documentclass{article}
\usepackage{minted}
\usepackage{caption}
\newenvironment{mylisting}[1][H]
  {\captionsetup{aboveskip=-0.2\normalbaselineskip}\begin{listing}[#1]}
  {\end{listing}}
\begin{document}
\bgroup
\captionsetup{aboveskip=-0.2\normalbaselineskip}
\begin{listing}[H]
\begin{minted}{c}
for i:=maxint to 0 do
begin
  { do nothing }
end;\end{minted}
\caption{Example of a listing.}\label{lst:example}
\end{listing}
\egroup
\begin{mylisting}[H]
\begin{minted}{c}
for i:=maxint to 0 do
begin
  { do nothing }
end;\end{minted}
\caption{Example of a listing.}\label{lst:example}
\end{mylisting}
\begin{figure}[!ht]
\captionsetup{aboveskip=60pt}
\centering
\rule{1cm}{1cm}% placeholder
\caption{A figure}
\end{figure}
\end{document}

No hay comentarios:

Publicar un comentario