![Не допускать размещения tcolorbox в нижней части страницы](https://rvso.com/image/400374/%D0%9D%D0%B5%20%D0%B4%D0%BE%D0%BF%D1%83%D1%81%D0%BA%D0%B0%D1%82%D1%8C%20%D1%80%D0%B0%D0%B7%D0%BC%D0%B5%D1%89%D0%B5%D0%BD%D0%B8%D1%8F%20tcolorbox%20%D0%B2%20%D0%BD%D0%B8%D0%B6%D0%BD%D0%B5%D0%B9%20%D1%87%D0%B0%D1%81%D1%82%D0%B8%20%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D1%8B.png)
Есть ли способ сделать так, чтобы tcolorbox не находился внизу страницы, а автоматически переносился на следующую страницу?
МВЭ:
\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
в 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}