Text FormattingAvoid Page Preak between Listing Border and first Line

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
knip
Posts: 2
Joined: Mon Mar 11, 2013 4:42 pm

Avoid Page Preak between Listing Border and first Line

Post by knip »

How is it possible to avoid a page break between the frame border and the first line of code as it is shown here?
listings-page-break.jpg
listings-page-break.jpg (56.6 KiB) Viewed 2622 times
Similarly, I have created a command to my examples that uses the package amsthm.

Code: Select all

\newcommand{\newExmp}[1]{
\vspace{1em}
\begin{samepage}
\hrule 
\begin{exmp}
#1
\end{exmp}
\hrule
\end{samepage}
\vspace{1em}
}
How is it possible to avoid a page break between the \hline and the first line of text (#1) and between last line of text and last \hline?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Avoid Page Preak between Listing Border and first Line

Post by localghost »

As already mentioned here, you should always provide a proper, self-contained and minimal example to make a problem comprehensible for others.

It would at least be helpful to know how you set up your listings.

And we would appreciate your feedback on proposed solutions to your questions.


Thorsten
Post Reply