tcolorbox가 페이지 하단에 위치하지 않도록 방지

tcolorbox가 페이지 하단에 위치하지 않도록 방지

tcolorbox가 페이지 하단에 있는 것을 방지하고 대신 자동으로 다음 페이지로 푸시하는 방법이 있습니까?

MWE:

\documentclass[a4paper, 10pt, oneside, twocolumn]{memoir}

\usepackage{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{outcome}{before skip=2em, after skip=1em}

\begin{document}

\section{Sample}

\begin{outcome}
    This is some sample text. This is some sample text. This is some sample text. 
\end{outcome}

\lipsum[1-6]

This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. 

\begin{outcome}
    Sample text.
\end{outcome}

This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. 

\end{document}

여기에 이미지 설명을 입력하세요

답변1

이 시도:

\makeatletter
\newtcolorbox{outcome}{before skip=2em, after={%
    \tcb@parfillskip@check\par\ifvmode\nointerlineskip
    \nobreak
    \addvspace{\glueexpr 1em-\parskip}\fi
    }}
\makeatother

after skip/.style코드는 in 의 정의에서 그대로 복사되며 tcolorbox.sty, #1하드 코딩된 값으로 대체되고 다음 단락과 함께 상자를 유지하기 위해 가 추가됩니다 1em.\nobreak

답변2

내 오래된 대답의 방법은 다음과 같습니다.여기:

\documentclass[a4paper, 10pt, oneside, twocolumn]{memoir}

\usepackage{tcolorbox}
\usepackage{lipsum}

\newsavebox{\mybottombox} % Box to save the text of the command 
\newlength{\mybottomlength} % The length of our text inside the command
\newlength{\availafter} % The available length left on the page after placing our text


% Optional argument is the minimum length after the nobottom text for not pagebreak. Change it to your needs
\newcommand{\nobottom}[2][60pt]{\savebox{\mybottombox}{\vbox{#2}}\setlength{\mybottomlength}{\ht\mybottombox}%
\setlength{\availafter}{\dimexpr\textheight-\mybottomlength-\pagetotal\relax}\ifdim\availafter<#1%
\pagebreak\noindent\usebox{\mybottombox}%
\else%
\noindent\usebox{\mybottombox}%
\fi%
}%

\newtcolorbox{outcome}{before skip=2em, after skip=1em}

\begin{document}

\section{Sample}

\begin{outcome}
    This is some sample text. This is some sample text. This is some sample text. 
\end{outcome}

\lipsum[1-6]

This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. 

\nobottom{%
\begin{outcome}
    Sample text.
\end{outcome}}

This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. This is some sample text. 

\end{document}

여기에 이미지 설명을 입력하세요

관련 정보