# Prevent a page break across two different environment

I need to tie two different environments, i.e., prevent a page break from happening. I tried \nopagebreak, \nobreak, \begin{samepage}-\end{samepage}, but nothing worked.

\begin{enumerate}
\item ....
\item týden
Pondělí:
\begin{enumerate}
\begin{multicols}{2}
\item $\frac{\frac{1}{a-1}+\frac{2}{a-1}+\frac{3}{a-1}}{\frac{1}{a^{2}-1}}$
\vysl{$6(a+1)$ PODM: $a\neq\pm1$}
\item $(y^{2}-2)^{3}$
\vysl{$y^{6}-6y^{4}+12y^{2}-8$}
\end{multicols}
\item $A-B=?;A=\{x\in\R;-3\leq x\leq 10\};B=\{x\in\R;-4<x<8\}$
\vysl{$A-B=\{x\in\R;8 \leq x\leq 10\}$}
\end{enumerate}


Page breaks somewhere between word "Pondělí" and environment multicols, but I need it together.

Thanks for all answers and excuse my English, I hope everything is understandable.

• Welcome to TeX.SE. Have you looked into the needspace package? – Mico Sep 28 '15 at 19:42

You should try the needspace package. Since it looks like 5 to 6 lines are occupied by the material that needs to be kept together, you might try:

\documentclass{article}
\usepackage{multicol,needspace}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%% how is the "\vysl" macro defined?

\begin{document}

\begin{enumerate}
\item \dots
\item týden
\needspace{6\baselineskip}
Pondělí:
\begin{enumerate}
\begin{multicols}{2}
\item $\frac{\frac{1}{a-1}+\frac{2}{a-1}+\frac{3}{a-1}}{\frac{1}{a^{2}-1}}$
\vysl{$6(a+1)$ PODM: $a\neq\pm1$}
\item $(y^{2}-2)^{3}$
\vysl{$y^{6}-6y^{4}+12y^{2}-8$}
\end{multicols}
\item $A-B=?;A=\{x\in\R;-3\leq x\leq 10\};B=\{x\in\R;-4<x<8\}$
\vysl{$A-B=\{x\in\R;8 \leq x\leq 10\}$}
\end{enumerate}

\end{document}


(I'm afraid I can't post a screenshot as I don't know how the \vsyl macro is defined.)