2

The question is close related to another question, where the accepted answer seems not to work for me. Hence I decided to post a new question here.

I'm using the minted package to generate highlighted code snippets which are framed and captioned above. An answer here suggests creating a new environment to make the caption work and I decide to use mdframed package to create the frame (since I'm not familiar with tcolorbox package). My problem is that the mdframed environment failed to break across the pages. The MWE turns out to do nothing about the minted package:

\documentclass{article}
\usepackage{mdframed}
\usepackage{caption}
% \usepackage{minted}% Not necessary
\usepackage{newfloat}% Only to define the listing float
\usepackage{lipsum}
\DeclareFloatingEnvironment{listing}
\captionsetup[listing]{
  position = above,
  skip = 0pt,
}
\newenvironment{longlisting}{\captionsetup{type=listing}}{}
\begin{document}
  \begin{longlisting}
    \captionof{listing}{Caption}
    \begin{mdframed}
      \lipsum[1-10]
    \end{mdframed}
  \end{longlisting}
\end{document}

Sorry, I'm working on how to upload the screenshots.

  • 1
    Are mdframe's even breakable by default? I'd also have a look at the tcolorbox package as it is probably much more configurable than mdframed – daleif Jun 30 '21 at 08:27
  • 1
    @daleif mdframed has an option for breakable boxes, but you are quite right that tcolorbox is much better, both in the set of features and in the behaviour. – Ulrike Fischer Jun 30 '21 at 09:45
  • @UlrikeFischer I know it has an option for it, we use it in some of our teaching material, just could not remember if it is active by default. – daleif Jun 30 '21 at 10:06
  • @daleif Yes, mdframed’s are breakable by default. mdframed provide an option named nobreak with the default value to be false. I’m going to take a look at tcolorbox package. Thanks! – Noto_Ootori Jun 30 '21 at 11:18

0 Answers0