mdframed:如果剩余内容(或初始内容)太小,如何防止框分裂?

mdframed:如果剩余内容(或初始内容)太小,如何防止框分裂?

问题

我想避免mdframed过早或过晚分割盒子。我的意思是,我希望盒子的剩余部分始终大于之前给出的固定长度。

使用 的正常选项似乎是不可能的mdframed

有人知道如何修改mdframed宏以使其具有此功能吗?

图片与代码

在此处输入图片描述

\documentclass[a5paper]{article}
\usepackage{mdframed}
\begin{document}

\begin{mdframed}[
innerrightmargin = 0.5cm, 
innertopmargin = 0.5cm, 
innerbottommargin = 0.5cm, 
innerleftmargin = 0.5cm, 
skipbelow = 5mm, 
skipabove = 5mm, 
userdefinedwidth = 5cm, 
splitbottomskip = 5mm, 
splittopskip = 5mm,
backgroundcolor = red,  
roundcorner = 5pt,
align = center]


Vestibulum lectus metus, tincidunt at fermentum non, pellentesque at lorem. Vivamus nisl sem, tempor ac mi et, elementum feugiat justo. Pellentesque tristique consequat molestie. Donec non porttitor risus. Praesent adipiscing elementum tortor, commodo ullamcorper justo consequat eget. Aenean eget nulla enim. Nam purus massa, hendrerit quis faucibus eget, consectetur ac dui. Curabitur ornare non ipsum elementum suscipit. Sed a dignissim ligula, nec vestibulum dui. Fusce sed varius tellus.

Vestibulum lectus metus, tincidunt at fermentum non, pellentesque at lorem. Vivamus nisl sem, tempor ac mi et, elementum feugiat justo.

Vestibulum lectus metus.

\end{mdframed}

This is after the \verb+mdframed+ environment.
\end{document}

答案1

我介绍一下\widow使用 来\widowpenalty防止单行挂起(除非整个段落只占一行)。您将其\widow作为段落的最后一个单词插入。这样,它不会应用于整个文档,而是在本地应用以解决本地问题。

同样的方法mdframed也适用于 之外。

\documentclass[a5paper]{article}
\usepackage{mdframed}
\newcommand\widow{%
  \widowpenalty=10000

  \widowpenalty=150}
\begin{document}

\begin{mdframed}[
innerrightmargin = 0.5cm, 
innertopmargin = 0.5cm, 
innerbottommargin = 0.5cm, 
innerleftmargin = 0.5cm, 
skipbelow = 5mm, 
skipabove = 5mm, 
userdefinedwidth = 5cm, 
splitbottomskip = 5mm, 
splittopskip = 5mm,
backgroundcolor = red,  
roundcorner = 5pt,
align = center]


Vestibulum lectus metus, tincidunt at fermentum non, pellentesque at lorem. Vivamus nisl sem, tempor ac mi et, elementum feugiat justo. Pellentesque tristique consequat molestie. Donec non porttitor risus. Praesent adipiscing elementum tortor, commodo ullamcorper justo consequat eget. Aenean eget nulla enim. Nam purus massa, hendrerit quis faucibus eget, consectetur ac dui. Curabitur ornare non ipsum elementum suscipit. Sed a dignissim ligula, nec vestibulum dui. Fusce sed varius tellus.

Vestibulum lectus metus, tincidunt at fermentum non, pellentesque at lorem. Vivamus nisl sem, tempor ac mi et, elementum feugiat justo.

Vestibulum lectus metus.\widow

\end{mdframed}

This is after the \verb+mdframed+ environment.
\end{document}

在此处输入图片描述


为了使答案对称,我有一个针对段落开头的孤儿问题的类似解决方案,可像\orphan在段落开头一样应用。

\usepackage{needspace}
\newcommand\needlines[1]{\needspace{#1\baselineskip}}
\newcommand\orphan{%
  \needlines{2}%
}

相关内容