1

I am trying to create boxes spanning over multiple pages considered as floats.

I defined boxes as floats which I can refer to using a \DeclareFloatingEnvironment. It works well.

I find a way to create box spanning multiple pages using the mdframed package. Thanks to boxes spanning several pages.

Captioning an mdframed box without making unbreakable is close but does not entirely answer my request since it does not encapsulate the box inside a floating environment I can refer to.

Here is a MWE that shows what I tried so far. The last box will not split:

\documentclass{article}

\usepackage{newfloat}

\DeclareFloatingEnvironment[
  fileext=lob,
  listname={List of boxes},
  name=Box,
  placement=htp,
]{myBox}

\usepackage{fancybox}

\newenvironment{encadrement}[1][\textwidth]
{\begin{Sbox}
        \centering
        \begin{minipage}{#1}}
{\end{minipage}
        \end{Sbox}
        \fbox{\TheSbox}}

\usepackage{mdframed}



\usepackage{blindtext}


\begin{document}

\blindtext

\begin{myBox}

    \caption{A small box   \label{box:smallBox}}


    \begin{encadrement}
     \blindtext
    \end{encadrement}


\end{myBox}

I can here refer to the Box~\ref{box:smallBox}.

\blindtext

A big box follows, but it has no caption nor label:

\begin{mdframed}
 \Blindtext
\end{mdframed}

\blindtext

% The following box will not split as I'd like
\begin{myBox}

    \caption{A big box   \label{box:bigBox}}


    \begin{mdframed}
     \Blindtext
    \end{mdframed}


\end{myBox}


\end{document}
4
  • 6
    latex floats can not split but if you have an environment that does split you can give it a referenceable caption, eg \captionof{figure}{my caption} from the caption package. Sep 13, 2019 at 9:43
  • Is this the final answer :-)? Thing is that I'd like to have the float numbered (there are already many boxes) - ie probably using the myBox environment ...
    – tuculuxu
    Sep 13, 2019 at 10:53
  • 1
    if you use \captionof{figure}{....} it will be numbered in sequence with figures (or use table or listings or whatever other counter you are using) Sep 13, 2019 at 11:33
  • Ok, now I understand! Thanks
    – tuculuxu
    Sep 15, 2019 at 20:40

1 Answer 1

2

To illustrate the use of \captionof with mdframed. One can make it act more like a float by using \afterpage and \clearpage (afterpage package).

\documentclass{article}
\usepackage{newfloat}
\usepackage{caption}

\DeclareFloatingEnvironment[
  fileext=lob,
  listname={List of boxes},
  name=Box,
  placement=htp,
]{myBox}

\usepackage{mdframed}
\usepackage{blindtext}

\mdfsetup{linewidth=1pt}% otherwise left line gets eaten.

\begin{document}

\blindtext

I can here refer to the Box~\ref{box:bigBox}.

\begin{mdframed}
  \captionof{myBox}{Now it has a caption and label}\label{box:bigBox}
  \Blindtext
\end{mdframed}

\blindtext

\end{document}
2
  • Great, thanks! Well, then I have two other questions ... 1/The caption is located within the box while using this method. Is there a way to put it outside the box? (Above). 2/ Fortunately, footnotes work amazingly within boxes (not sure how but thats great). However, now, with a mdframed box, they are all located at the very end of the box, not on the page of the footnote letter (it's a letter within a box). Would you have an idea?
    – tuculuxu
    Sep 15, 2019 at 20:43
  • You could create the contents of the box as a separate document, then copy the pages one at a time using \includegraphics[page=...]{...}. Of course the footnotes numbers would be local to the box, and the \textwidth and \textheight will need to be reduced to fit inside the box. Sep 16, 2019 at 14:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .