![Verhindern, dass tcolorbox am unteren Ende einer Seite angezeigt wird](https://rvso.com/image/400374/Verhindern%2C%20dass%20tcolorbox%20am%20unteren%20Ende%20einer%20Seite%20angezeigt%20wird.png)
Gibt es eine Möglichkeit, zu verhindern, dass eine Farbbox am unteren Ende einer Seite angezeigt wird, und sie stattdessen automatisch auf die nächste Seite zu verschieben?
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}
Antwort1
Versuche dies:
\makeatletter
\newtcolorbox{outcome}{before skip=2em, after={%
\tcb@parfillskip@check\par\ifvmode\nointerlineskip
\nobreak
\addvspace{\glueexpr 1em-\parskip}\fi
}}
\makeatother
Der Code wird wortwörtlich aus der Definition von after skip/.style
in kopiert tcolorbox.sty
, #1
durch Ihren fest codierten Wert ersetzt 1em
und ein \nobreak
hinzugefügt, um das Feld mit dem folgenden Absatz zusammenzuhalten.
Antwort2
Hier ist ein Weg von meiner alten AntwortHier:
\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}