5

In the standard article class the distance between caption and the listing below it is fine. But when using KOMA-Script's documentclass scrartcl the vertical space is too big (see the image below). I'm using minted package and the code is inside listing environment.

Q: What is the easiest way to adjust the vertical spacing between the caption and the floating listing?

If that can be achieved without using listing environment, that is also fine. And here is the MWE:

\documentclass[12pt,a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[newfloat]{minted}

\begin{document}
\begin{listing}
\caption{Code sample}
\begin{minted}[frame=lines]{js}
function foo() {
  return;
}
\end{minted}
\end{listing}
\end{document}

Too much vertical space below caption

PS. I have identical problem with figures where the caption is too far below the figure. That might be a related case.

EDIT: I have tried to fix this using caption package with no luck. I have no idea where to look next.

EDIT2: I know some programming. So if there is a way to redefine some KOMA macros, I'd like to try it. But I don't know where to start debugging...

  • As it seems there is an option for listings, see here: tex.stackexchange.com/q/61413/4736 Does this answer your question? – Keks Dose Jul 20 '16 at 11:55
  • Hmm, not sure that'll help. I'm not using listings package but listing environment which (I guess) is provided by mintedpackage. I also tried adding captions package but various skip parameters moved both the listing and the caption. – Paapaa Jul 21 '16 at 22:00
2

I cannot reproduce your example image. With scrartcl the distance I get is very consistent comparing, e.g., tables with headings:

\documentclass[12pt,a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[newfloat]{minted}

\begin{document}
\begin{listing}
\caption{Code sample}
\begin{minted}[frame=lines]{js}
function foo() {
  return;
}
\end{minted}
\end{listing}
\end{document}

example with table and listing

Nevertheless, minted with option newfloat uses package newfloat, that is part of the caption bundle. You can use caption to configure the captions of the listing environment, e.g.:

\documentclass[12pt,a4paper,captions=tableheading]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[newfloat]{minted}
\usepackage{caption}
\captionsetup[listing]{position=top,skip=-10pt}% move caption of listing toward listing

\begin{document}
\begin{listing}
\caption{Code sample}
\begin{minted}[frame=lines]{js}
function foo() {
  return;
}
\end{minted}
\end{listing}

\captionsetup[listing]{position=top,skip=10pt}% move caption away from caption
\begin{listing}
\caption{Code sample}
\begin{minted}[frame=lines]{js}
function foo() {
  return;
}
\end{minted}
\end{listing}
\end{document}

enter image description here

  • It fixed my problem, thanks!!!!! – user Oct 9 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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