mdframed 中的大量内容

mdframed 中的大量内容

我知道这可能不是预期的用例,但我使用以下 MWE 得到了奇怪的分页符(也使用今天的版本 1.6c 进行了测试):

\documentclass{article}

\usepackage{mdframed}

\newcommand{\SmallBox}{%
  \begin{minipage}[t]{0.9\linewidth}
    top

    \vspace*{2.5in}

    bottom
  \end{minipage}%
}

\newcommand{\BigBox}{%
  \begin{mdframed}
    \SmallBox

    \noindent\SmallBox
  \end{mdframed}%
}

\begin{document}

\BigBox

\BigBox

\end{document}

至于我为什么要这样做:我有一些想要装框的物品,但有时它们以 tikz 图片和小页面中的一些附带文本开头和/或结尾。这种材料不能分割,所以当我的物品靠近页面底部时,我经常会得到类似于我发布的示例的东西。我一直在强迫它们在这种情况下不破裂,但我希望有办法解决这个问题(因为当我添加内容时,靠近页面底部的物品会发生变化,所以我经常必须修改哪些框是不可破坏的。)

有没有办法避免手动执行此操作?这是一个错误,还是我使用得太脱离上下文了。

答案1

请测试以下重新定义:

\makeatletter
\def\mdf@put@frame@i{%Box must be splitted
 \mdf@freepagevspace%gives \mdf@freevspace@length
 \dimen@=\the\mdf@freevspace@length\relax%
 \dimen@i=\mdf@innertopmargin@length\relax%
 \advance\dimen@i by \mdf@innerlinewidth@length\relax%
 \advance\dimen@i by \mdf@middlelinewidth@length\relax%
 \advance\dimen@i by \mdf@outerlinewidth@length\relax%
 \advance\dimen@i by 2\baselineskip\relax%
 \ifdimless{\dimen@}{\dimen@i}%
   {\hrule \@height\z@ \@width\hsize%
    \vfill\eject%
    \def\mdf@reserved@a{\mdf@put@frame}%
   }%
   {%
    \mdf@dolist{\mdf@advancelength@freevspace@sub}{%calculate with \dimen@
              outerlinewidth,middlelinewidth,innerlinewidth,%
              innertopmargin,splitbottomskip}%
    \ifbool{mdf@everyline}%
      {%
       \ifbool{mdf@bottomline}%
          {%
           \advance\dimen@ by -\mdf@innerlinewidth@length%
           \advance\dimen@ by -\mdf@middlelinewidth@length%
           \advance\dimen@ by -\mdf@outerlinewidth@length%
          }{}%
      }{}%
    \notbool{mdf@topline}%
       {%
        \advance\dimen@ by \mdf@innerlinewidth@length%
        \advance\dimen@ by \mdf@middlelinewidth@length%
        \advance\dimen@ by \mdf@outerlinewidth@length%
       }{}%
    \advance\[email protected]\pageshrink
    \ifdimless{\ht\mdf@splitbox@one+\dp\mdf@splitbox@one}{\dimen@}%
       {\mdf@PackageWarning{You got a bad break\MessageBreak
                            because the last box will be empty\MessageBreak
                           you have to change it manually\MessageBreak
                           by changing the text, the space\MessageBreak
                           or something else}%
        \advance\dimen@ by -1.8\baselineskip\relax%needed????????????????????
       }{}%
    \setbox\mdf@splitbox@save=\vbox{\unvcopy\mdf@splitbox@one}%
    \splitmaxdepth\z@ \splittopskip\mdf@splittopskip@length%
    \mdf@ignorevbadness%
    \setbox\mdf@splitbox@two\vsplit\mdf@splitbox@one to \dimen@
    \setbox\mdf@splitbox@two\vbox{\unvbox\mdf@splitbox@two}%
    \setbox\mdf@splitbox@one\vbox{\unvbox\mdf@splitbox@one}%
    \ifdimgreater{\ht\mdf@splitbox@two+\dp\mdf@splitbox@two}{\dimen@}%
      {%splitted wrong
       \mdf@PackageInfo{Box was splittet wrong^^J
                        starting loop to iterate
                        the splitting point\MessageBreak}%
       \setbox\mdf@splitbox@one=\vbox{\unvcopy\mdf@splitbox@save}%
       \dimen@i=\dimen@%\relax
       \@tempcnta=\z@\relax
       \loop
        \ifdim\dimexpr\ht\mdf@splitbox@two+\dp\mdf@splitbox@two\relax>\dimen@
          \advance\dimen@i by -\p@\relax
          \advance\@tempcnta by \@ne\relax
          \mdf@ignorevbadness%
          \setbox\mdf@splitbox@one=\vbox{\unvcopy\mdf@splitbox@save}%
          \splitmaxdepth\z@ \splittopskip\mdf@splittopskip@length%
          \mdf@ignorevbadness%
          \setbox\mdf@splitbox@two\vsplit\mdf@splitbox@one to \dimen@i\relax%
          \setbox\mdf@splitbox@two\vbox{\unvbox\mdf@splitbox@two}%
          \setbox\mdf@splitbox@one\vbox{\unvbox\mdf@splitbox@one}%
          \ifnum\@tempcnta>100
            \let\iterate\relax
            \mdf@PackageWarning{correct box splittet fails^^J
                                It seems you are using a non splittable
                                contents\MessageBreak}
          \setbox\mdf@splitbox@one=\vbox{\unvcopy\mdf@splitbox@save}%
          \setbox\mdf@splitbox@two=\vbox{}%
          \def\mdf@reserved@a{\mdf@put@frame}%
         \fi
       \repeat%
      }{}%
    \ifvoid\mdf@splitbox@one\relax%
      \mdf@PackageWarning{You got a bad break because the splittet box
                          is empty^^J
                          You have to change the page settings^^J
                          like enlargethispage or something else^^J
                          the package increases do
                          \enlargethispage{\baselineskip}\MessageBreak}%
      \setbox\mdf@splitbox@one=\vbox{\unvcopy\mdf@splitbox@save}
      \enlargethispage{\baselineskip}%
      \def\mdf@reserved@a{\mdf@put@frame}%
    \fi%
    \ifdim\wd\mdf@splitbox@two=\wd\mdf@splitbox@one\relax
    \else%
      \mdf@PackageInfo{You first box width is to small^^J
                       mdframed fixed it\MessageBreak}%
      \setbox\mdf@splitbox@two=\vbox%
                   {%
                    \hrule \@height\z@ \@width\wd\mdf@splitbox@one\relax
                    \unvcopy\mdf@splitbox@two%
                   }%
    \fi%
    \ifvoid\mdf@splitbox@two\relax%
        {\hrule \@height\f@size pt \@width\z@%
         \hrule \@height\z@ \@width\hsize}%
         \setbox\mdf@splitbox@one=\vbox{\unvcopy\mdf@splitbox@save}%
         \def\mdf@reserved@a{\mdf@put@frame}%
     \else%
        \ifdimequal{\ht\mdf@splitbox@two}{0pt}%
          {\hrule \@height\z@ \@width\hsize%
           \vfill\eject%
           \setbox\mdf@splitbox@one=\vbox{\unvcopy\mdf@splitbox@save}%
           \def\mdf@reserved@a{\mdf@put@frame}%
          }%
          {%
          \begingroup\mdf@@setzref\mdf@putbox@first\endgroup%
          \hrule \@height\z@ \@width\hsize%
          \vfill\eject%
          \def\mdf@reserved@a{\mdf@put@frame@ii}%
          }%
     \fi%
   }%
\mdf@reserved@a%
}
\makeatother

相关内容