セクション見出しの後にmdframedを使用する

セクション見出しの後にmdframedを使用する

以下は非常に不自然な例ですが、パッケージでは解決できない問題を示していますmdframedmdframed環境がセクション見出しの後にあっても、コンテンツ環境を配置する十分なスペースがない場合、セクション見出しは孤立してしまいます。

mdframedまたは他のものに置き換えてもminipage孤立文字は生成されず、変更しても\clubpenalty効果はありません。

たとえば、環境に 1 行しか含まれていなくても、skipaboveまたはの値が大きい場合innertopmargin、同じ結果になります。以下の MWE で使用する改行不可能なコンテンツは、結果を簡単に示すためのものです。

\documentclass{article}

\usepackage{mdframed}

\newcommand{\BoxContents}{top\par\vspace*{2in}bottom}

\begin{document}

\vspace*{5in}

\section{Section}

\begin{mdframed}% this orphans the section heading
    \BoxContents
\end{mdframed}

\newpage

\vspace*{5in}

\section{Section}

\begin{minipage}[t]{\linewidth}% this does not orphan the section heading
    \BoxContents
\end{minipage}

\end{document}

このような状況が発生したときに、手動でページを分割せずに、セクション見出しに続いてこの環境を使用する方法はありますか?

答え1

チャットルームでデビッド・カーライルそしてエグレ問題を指摘するのに役立ちました。ご協力ありがとうございました。

通常は\section、孤児を回避するために中断することはありません。通常は例外があることを意味します。

色の指定を可能にするには、不要なブレークポイントを購入する必要があります。これを説明するために、次の例を使用します。

\documentclass{article}
\begin{document}
\showoutput\setbox0\vbox{%
\section{Section}

\penalty10000
\begin{minipage}[t]{\linewidth}
    top\par\vspace*{2in}bottom
\end{minipage}
}\showbox0
\end{document}

ファイルにはlog次の内容が含まれています:

.\write1{\@writefile{toc}{\protect \contentsline {section}{\protect \numberline
 \ETC.}
.\penalty 10000
.\glue 9.90276 plus 0.86108
.\penalty 10000
.\glue(\parskip) 0.0 plus 1.0
.\glue(\baselineskip) 5.84921

ここで、 を使用するように例を変更しますmdframed

\documentclass{article}
\usepackage{mdframed}
\begin{document}
\showoutput\setbox0\vbox{%
\section{Section}

\penalty10000

\begingroup\color{red}
\begin{minipage}[t]{\linewidth}
    top\par\vspace*{2in}bottom
\end{minipage}
\endgroup
}\showbox0

\showoutput\setbox0\vbox{
\section{Sectionaa}

\penalty10000
\begin{mdframed}% this orphans the section heading
    top\par\vspace*{2in}bottom
\end{mdframed}
}\showbox0
\end{document}

ファイル内の出力は次のとおりlogです。

.\write1{\@writefile{toc}{\protect \contentsline {section}{\protect \numberline
 \ETC.}
.\penalty 10000
.\glue 9.90276 plus 0.86108
.\penalty 10000
.\rule(0.0+0.0)x345.0
.\pdfcolorstack 0 push {0 g 0 G}
.\glue 0.0
.\glue(\parskip) 0.0
.\hbox(0.0+0.0)x345.0, glue set 345.0fil

が確認できますglue 0。ここでブレークが発生します。! を避けることはできませんglue 0。ここでの例に基づくと、minipageを変更すると同じ問題が発生します。

\documentclass{article}
\usepackage{color}
\begin{document}
\vspace*{5in}

\section{Section}
\begingroup\color{red}
\begin{minipage}[t]{\linewidth}
    top\par\vspace*{2in}bottom
\end{minipage}
\endgroup

\end{document}

つまり、色の使用に基づく問題です。

関連情報