I already read How can I prevent breaks in a custom environment? but this somehow does not solve my problem. I want to define an environment that defines a heading and then there is one line of text and a huge AVM. All of this has to stay on the same page. I tried samepage but LaTeX is stubborn and breaks anyway. I tried minipage but then the space before and after the environment is gone.
\documentclass{article}
\usepackage{array}
\newcounter{schema}
\newenvironment{schema}[1][]
{% \begin{schema}[<title>]
\goodbreak%
\refstepcounter{schema}%
\begin{list}{}{\setlength{\labelwidth}{0pt}\setlength{\labelsep}{0pt}\setlength{\rightmargin}{0pt}\setlength{\leftmargin}{0pt}}%
\item[{\textbf{Schema~\theschema}}]\hspace{.5em}\textbf{(#1)}\nopagebreak[4]\par\nobreak}%
{\end{list}}% \end{schema}
\newcommand{\onems}[2][]{%
\mbox{%
\delimiterfactor=1000 \delimitershortfall=0pt
\tabcolsep=0pt
$\left[%
\begin{tabular}{>{\upshape\scshape}l}
\if\relax\detokenize{#1}\relax\else
{\normalfont\itshape #1}%
\\
\fi
#2%
\end{tabular}%
\right]$%
}%
\vspace{1mm}%
}
\begin{document}
\begin{schema}[Head-Complement Schema]
\label{schema-hc-flat}
\textit{head-complement-phrase}\\*
\onems{
synsem|loc|cat|comps <>\\
head-dtr \onems{ synsem|loc|cat|comps 1\\
}\\
non-head-dtrs synsem2signs(1)\\
}
\end{schema}
\end{document}
Edit: This is the version of the code with minipage wrapper (commented out). The minipage version eats the space before and after the environment. I do not know how to fix this.
\documentclass{article}
\usepackage{array,lipsum}
\newcounter{schema}
\newenvironment{schema}[1][]
{% \begin{schema}[<title>]
\goodbreak%
\refstepcounter{schema}%
\begin{list}{}{\setlength{\labelwidth}{0pt}\setlength{\labelsep}{0pt}\setlength{\rightmargin}{0pt}\setlength{\leftmargin}{0pt}}%
\item[{\textbf{Schema~\theschema}}]\hspace{.5em}\textbf{(#1)}\nopagebreak[4]\par\nobreak}%
{\end{list}}% \end{schema}
%% \newenvironment{schema}[1][]
%% {% \begin{schema}[<title>]
%% \goodbreak%
%% \refstepcounter{schema}%
%% \begin{minipage}{\linewidth}%
%% \begin{list}{}{\setlength{\rightmargin}{\leftmargin}}%
%% \item[{\textbf{Schema~\theschema:}}]#1\par\nobreak}%
%% {\end{list}\end{minipage}}% \end{schema}
\newcommand{\onems}[2][]{%
\mbox{%
\delimiterfactor=1000 \delimitershortfall=0pt
\tabcolsep=0pt
$\left[%
\begin{tabular}{>{\upshape\scshape}l}
\if\relax\detokenize{#1}\relax\else
{\normalfont\itshape #1}%
\\
\fi
#2%
\end{tabular}%
\right]$%
}%
\vspace{1mm}%
}
\begin{document}
\lipsum[2]
\begin{schema}[Head-Complement Schema]
\label{schema-hc-flat}
\textit{head-complement-phrase}\\*
\onems{
synsem|loc|cat|comps <>\\
head-dtr \onems{ synsem|loc|cat|comps 1\\
}\\
non-head-dtrs synsem2signs(1)\\
}
\end{schema}
\lipsum[2]
\end{document}

minipageor\parbox. You say you "tried minipage but then the space before and after the environment is gone". It would be best you posted this MWE and we can take it from there. – campa Dec 06 '19 at 13:06