I would like to design a simple environment which displays examples.This is what I got so far:
\documentclass{article}\usepackage{xcolor}\usepackage{parskip}\usepackage{lipsum}\makeatletter \newcommand\filltoend{\leavevmode\leaders\hrule height 0.7ex depth \dimexpr0.4pt-0.7ex\hfill\kern0pt} \newcounter{example} \newenvironment{example}[1][]{% \refstepcounter{example}% \textbf{Example~\theexample{}}~{\color{gray}\filltoend}% number and line \nopagebreak% is this the right place? \par% should I call other vertical spacing commands so I can use the plus/minus syntax? \textbf{#1}% Heading \par\itshape\ignorespaces% }{% \\% it would be nice to keep this together with contents {\color{gray}\null\filltoend\null} }\makeatother\begin{document}\lipsum[1-4]\begin{example}[My example] \lipsum[5]\end{example}\end{document}
This is simple and kind of ok.
How can I specify that I want some non-strechable vertical space between the example's number and line, heading and text?How do I discourage LaTeX from putting page breaks between the header components?
In other words: I would like to keep the Example # ---
, heading, and start of inner paragraph together, on the same page and without too large spacing between them.