0

I see some similarities to other questions (1 and 2), but I think this is distinct. When I use mdframed and multicol together, I sometimes get bizarre unintended pagebreaks. Here is a MWE:

\documentclass[10pt,letterpaper]{article}
\usepackage[margin=1in]{geometry}
\usepackage{multicol}
\usepackage{mdframed}

\newcount\myloopcounter
\newcommand{\repeatit}[2][10]{%
\myloopcounter0% initialize the loop counter
\loop\ifnum\myloopcounter < #1 % Test if the loop counter is < #1
#2%
\advance\myloopcounter by 1 % 
\repeat % start again
}

\begin{document}
\begin{multicols}{2}
\repeatit[30]{
\vspace{0.3cm}
\begin{mdframed}
\vspace{3cm}
\end{mdframed}
}
\end{multicols}
\end{document}

Credit to Christian Hupfer's answer to another question for repeatit which allows me to express this MWE more concisely. When I run this MWE, I get 10 frames on the first page. Then I get only one frame on the second page before it breaks to the third page. Just one frame on the fourth page, and then the frames on the fifth page are misaligned. What's going on?

A few additional details: Sometimes I don't get any weird page breaks. It seems to depend on how everything fits in the page before the break occurs. Also, sometimes the weird page break appears within a frame, so there is just 2/3 of a frame on one page, and then the frame resumes on the next page.

  • Thanks for the credits to my answer there -- it was however not meant to be used this way with multicols etc. Depending what you're really after, a tcbraster from tcolorbox package can be easier here! – user31729 Aug 8 '16 at 20:51
  • @ChristianHupfer In my actual document, I don't use it. I just use it here for a MWE because it saves me having 30 blank boxes. That's to say that the strange behavior I'm seeing occurs without repeatit, which I only use to demonstrate the behavior cleanly in the MWE. – Shane Aug 8 '16 at 21:06
1
+50

You can get around the problem by adding an additional box:

\documentclass[10pt,letterpaper]{article}
\usepackage[margin=1in]{geometry}
\usepackage{multicol}
\usepackage{mdframed}

\newcount\myloopcounter
\newcommand{\repeatit}[2][10]{%
\myloopcounter0% initialize the loop counter
\loop\ifnum\myloopcounter < #1 % Test if the loop counter is < #1
#2%
\advance\myloopcounter by 1 %
\repeat % start again
}

\begin{document}
\begin{multicols}{2}
\repeatit[30]{%
\vspace{0.3cm}
\noindent
\begin{minipage}{\linewidth}
\begin{mdframed}
\vspace{3cm}
\end{mdframed}
\end{minipage}\par
}
\end{multicols}
\end{document}

But I would instead follow the advice of Christian and use tcolorbox -- it is much more stable than mdframed.

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.