[Tex/LaTex] How to get caption above listing with minted

captionsmintedpositioning

I'm using the minted package. How can I get the caption to show before the code in the document?

\documentclass[a4paper]{scrartcl}
\usepackage{minted}
\begin{document}
    \begin{listing}[H]
        \caption{This is below the code.}
        \inputminted{matlab}{myfile.m}
        \label{lst:the-code}
    \end{listing}
\end{document}

Best Answer

The floatrow package will do the trick, but it must be loaded before minted to prevent it from loading the float package.

\documentclass[a4paper]{scrartcl}    
\usepackage{floatrow}
\usepackage{minted}    
\floatsetup[listing]{style=Plaintop}    
\begin{document}    
    \begin{listing}[H]    
        \caption{This is above the code.}    
        \inputminted{matlab}{myfile.m}    
        \label{lst:the-code}    
    \end{listing}    
\end{document}

enter image description here

Related Question