
以下是一個非常人為的範例,但它說明了我無法使用該mdframed
套件解決的問題。當mdframed
環境遵循節標題但沒有足夠的空間放置內容環境時,節標題將被孤立。
替換mdframed
為minipage
或其他任何內容都不會導致孤兒,並且更改\clubpenalty
也沒有效果。
例如,如果環境僅包含一行但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}
所以這個問題是基於顏色的使用。