防止在自定义环境中出现列中断

防止在自定义环境中出现列中断

我的文档分为两列(或更多列),文档由自定义环境中的文本块组成。每个文本块都不是很大,其中几个文本块可以轻松放入一列中。我更喜欢将此自定义环境视为不可分割的块。然而,它们有时会流到下一列(或页面)。我通常会在该文本块之前强制分栏,\vfill\null\columnbreak这样就没问题了。

我想知道是否可以自动执行此操作。我可以使用某些命令重新定义我的自定义环境,以便它完整地流到下一列(或页面)而不会中断。

假设我的环境名为intact。在 MWE 中,第三个intact块被破坏。我可以暂时阻止它......但只能在之前的块没有被修改之前。

我可以改变它自身的定义intact来解决这个问题吗?

\documentclass{article}
\usepackage{multicol}

\newenvironment{intact}[1]{
    \textbf{\underline{#1}}
}{
    \hrule
}

\newcommand{\sampletext}{You talkin to me? You talkin to me? Well I'm the only one here. Who the hell you talkin to? You talkin to me? You talkin to me? Well I'm the only one here. Who the hell you talkin to?}

\begin{document}
    Let there be light ...
    \begin{multicols}{2}
        \begin{intact}{First}
            \sampletext 
        \end{intact}
        \begin{intact}{Second}
            \sampletext 
        \end{intact}
        %\vfill\null\columnbreak % uncommenting this line resolves the problem temporarily i.e, till any of the above "intact"s is not modified.
        \begin{intact}{Third}
            \sampletext 
        \end{intact}
        \begin{intact}{Fourth}
            \sampletext 
        \end{intact}
        \begin{intact}{Fifth}
            \sampletext 
        \end{intact}
    \end{multicols}
\end{document}

在此处输入图片描述

答案1

把它放进 怎么样minipage

\documentclass{article}
\usepackage{multicol}
\newlength{\oldindent}
\setlength{\oldindent}{\parindent}

\newenvironment{intact}[1]{%
    \noindent\begin{minipage}[b]{\linewidth}
    \setlength{\parindent}{\oldindent}\textbf{\underline{#1}}
}{%
    \vspace{5pt}\hrule\vspace{4pt}
    \end{minipage}
}

\newcommand{\sampletext}{You talkin to me? You talkin to me? Well I'm the only one here. Who the hell you talkin to? You talkin to me? You talkin to me? Well I'm the only one here. Who the hell you talkin to?}

\begin{document}
    Let there be light ...
    \begin{multicols}{2}
        \begin{intact}{First}
            \sampletext
        \end{intact}
        \begin{intact}{Second}
            \sampletext 
        \end{intact}
        %\vfill\null\columnbreak % uncommenting this line resolves the problem temporarily i.e, till any of the above "intact"s is not modified.
        \begin{intact}{Third}
            \sampletext 
        \end{intact}
        \begin{intact}{Fourth}
            \sampletext 
        \end{intact}
        \begin{intact}{Fifth}
            \sampletext 
        \end{intact}
    \end{multicols}
\end{document}

在此处输入图片描述

相关内容